2015-02-23 21:57:05 +01:00
|
|
|
require "rubella/storage"
|
|
|
|
|
2015-02-17 22:03:32 +01:00
|
|
|
module Rubella
|
|
|
|
|
2015-02-19 18:30:09 +01:00
|
|
|
# Helps to process and create the heatmap
|
|
|
|
#
|
2015-02-17 22:03:32 +01:00
|
|
|
class Map
|
2015-02-17 22:28:31 +01:00
|
|
|
attr_reader :input
|
|
|
|
attr_reader :output
|
|
|
|
attr_reader :weighting
|
2015-02-17 22:03:32 +01:00
|
|
|
|
2015-02-19 18:30:09 +01:00
|
|
|
# Constructor
|
|
|
|
#
|
|
|
|
# @param input_name string Name of the input type in CamelCase
|
|
|
|
# @param output_name string Name of the output type in CamelCase
|
|
|
|
# @param weighting_name string Name of the weighting type in CamelCase
|
|
|
|
# @return Rubella::Map
|
|
|
|
# @raise NotImplementedError
|
2015-02-17 22:28:31 +01:00
|
|
|
def initialize(input_name, output_name, weighting_name)
|
2015-02-17 22:03:32 +01:00
|
|
|
|
2015-02-17 23:01:49 +01:00
|
|
|
# set the input type
|
2015-02-19 07:55:03 +01:00
|
|
|
input_by_name input_name
|
2015-02-17 22:03:32 +01:00
|
|
|
|
2015-02-17 23:01:49 +01:00
|
|
|
# set the output type
|
2015-02-19 17:30:22 +01:00
|
|
|
output_by_name output_name
|
2015-02-19 18:07:03 +01:00
|
|
|
|
2015-02-17 23:01:49 +01:00
|
|
|
# set the weighting
|
2015-02-19 18:07:03 +01:00
|
|
|
weighting_by_name weighting_name
|
2015-02-17 22:28:31 +01:00
|
|
|
|
2015-02-17 22:03:32 +01:00
|
|
|
end
|
|
|
|
|
2015-02-19 07:28:35 +01:00
|
|
|
# Creates a heatmap in the on construction given format. The data must be
|
|
|
|
# in the also on construction given formate.
|
|
|
|
#
|
|
|
|
# @param data string The data, which should be used
|
|
|
|
# @return binaryblob An output representation of the heatmap
|
2015-02-18 22:20:19 +01:00
|
|
|
def create_from_string data
|
2015-02-18 22:45:02 +01:00
|
|
|
process @input.string data
|
2015-02-18 22:20:19 +01:00
|
|
|
end
|
|
|
|
|
2015-02-19 07:28:35 +01:00
|
|
|
# Creates a heatmap in the on construction given format. The data must be
|
|
|
|
# in the also on construction given formate.
|
|
|
|
#
|
|
|
|
# @param file_name string
|
|
|
|
# @return binaryblob An output representation of the heatmap
|
2015-02-18 22:20:19 +01:00
|
|
|
def create_from_file file_name
|
2015-02-18 22:45:02 +01:00
|
|
|
process @input.file file_name
|
|
|
|
end
|
|
|
|
|
2015-02-19 07:28:35 +01:00
|
|
|
# Processes the creation of the heatmap, after the construction of the input
|
|
|
|
# object. So the input object is given here as parameter.
|
|
|
|
#
|
|
|
|
# @param inpt Input The inputed data
|
|
|
|
# @return binaryblob An output representation of the heatmap
|
2015-02-18 22:45:02 +01:00
|
|
|
def process inpt
|
|
|
|
weight = @weighting.new 10
|
2015-02-18 23:45:53 +01:00
|
|
|
outpt = @output.new
|
|
|
|
outpt.create weight.parse(inpt)
|
2015-02-18 22:20:19 +01:00
|
|
|
end
|
|
|
|
|
2015-02-19 07:55:03 +01:00
|
|
|
# Set the input type by the given name
|
|
|
|
#
|
2015-02-19 17:30:22 +01:00
|
|
|
# @param input_name string Name of the input type in CamelCase
|
|
|
|
# @raise NotImplementedError
|
2015-02-19 07:55:03 +01:00
|
|
|
def input_by_name input_name
|
2015-02-19 17:22:47 +01:00
|
|
|
@input = load_by_name "Input", input_name
|
|
|
|
end
|
|
|
|
|
2015-02-19 17:30:22 +01:00
|
|
|
# Set the output type by the given name
|
|
|
|
#
|
|
|
|
# @param output_name string Name of the output type in CamelCase
|
|
|
|
# @raise NotImplementedError
|
|
|
|
def output_by_name output_name
|
|
|
|
@output = load_by_name "Output", output_name
|
|
|
|
end
|
|
|
|
|
2015-02-19 18:07:03 +01:00
|
|
|
# Set the weighting type by the given name
|
|
|
|
#
|
|
|
|
# @param weighting_name string Name of the weighting type in CamelCase
|
|
|
|
# @raise NotImplementedError
|
|
|
|
def weighting_by_name weighting_name
|
|
|
|
@weighting = load_by_name "Weighting", weighting_name
|
|
|
|
end
|
|
|
|
|
2015-02-19 17:22:47 +01:00
|
|
|
# Loads and returns the given class
|
|
|
|
#
|
|
|
|
# @param module_name string The Name of the module in CamelCase
|
|
|
|
# @param class_name string The Name of the class in CamelCase
|
|
|
|
# @return Class
|
|
|
|
# @raise NotImplementedError
|
|
|
|
def load_by_name module_name, class_name
|
|
|
|
# Remove the class, if someone wants to do this
|
|
|
|
if class_name == nil or class_name == ""
|
|
|
|
return nil
|
2015-02-19 07:55:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# Try to load the given class
|
2015-02-19 18:07:03 +01:00
|
|
|
require "rubella/"+underscore(module_name)+"/"+underscore(class_name)
|
2015-02-19 07:55:03 +01:00
|
|
|
|
|
|
|
# Try to get a class by the given name
|
2015-02-19 17:22:47 +01:00
|
|
|
return Object.const_get("Rubella").const_get(module_name).const_get(class_name)
|
2015-02-19 07:55:03 +01:00
|
|
|
|
2015-02-19 18:07:03 +01:00
|
|
|
# TODO raise this error, if class is not found
|
2015-02-19 07:55:03 +01:00
|
|
|
# raise NotImplementedError, "Not supported input type "+input_name+" given"
|
2015-02-17 22:03:32 +01:00
|
|
|
end
|
|
|
|
|
2015-02-19 18:07:03 +01:00
|
|
|
# Converts CamelCase words into snake_case
|
|
|
|
#
|
|
|
|
# @param camel_cased_word string Word in CamelCase
|
|
|
|
# @return string
|
|
|
|
def underscore(camel_cased_word)
|
|
|
|
camel_cased_word.to_s.gsub(/::/, '/').
|
|
|
|
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
|
|
|
tr("-", "_").downcase
|
2015-02-17 22:03:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2015-02-19 18:07:03 +01:00
|
|
|
end
|