Use load_by_name also for Weighting
Plus add a functionallity to convert CamelCase into snake_case.
This commit is contained in:
parent
aea2b5bb3c
commit
8ac724a4c0
|
@ -12,21 +12,9 @@ module Rubella
|
||||||
|
|
||||||
# set the output type
|
# set the output type
|
||||||
output_by_name output_name
|
output_by_name output_name
|
||||||
|
|
||||||
# set the weighting
|
# set the weighting
|
||||||
@weighting = case weighting_name
|
weighting_by_name weighting_name
|
||||||
# add the option to set the weighting later
|
|
||||||
when nil then
|
|
||||||
nil
|
|
||||||
when "per_value" then
|
|
||||||
self.weighting_per_value
|
|
||||||
when "per_overall_load" then
|
|
||||||
self.weighting_per_overall_load
|
|
||||||
when "expotential" then
|
|
||||||
self.weighting_expotential
|
|
||||||
else
|
|
||||||
raise NotImplementedError, "Not supported weighting type "+weighting_name+" given"
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -75,6 +63,14 @@ module Rubella
|
||||||
@output = load_by_name "Output", output_name
|
@output = load_by_name "Output", output_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
# Loads and returns the given class
|
# Loads and returns the given class
|
||||||
#
|
#
|
||||||
# @param module_name string The Name of the module in CamelCase
|
# @param module_name string The Name of the module in CamelCase
|
||||||
|
@ -88,29 +84,24 @@ module Rubella
|
||||||
end
|
end
|
||||||
|
|
||||||
# Try to load the given class
|
# Try to load the given class
|
||||||
require "rubella/"+module_name.downcase+"/"+class_name.downcase
|
require "rubella/"+underscore(module_name)+"/"+underscore(class_name)
|
||||||
|
|
||||||
# Try to get a class by the given name
|
# Try to get a class by the given name
|
||||||
return Object.const_get("Rubella").const_get(module_name).const_get(class_name)
|
return Object.const_get("Rubella").const_get(module_name).const_get(class_name)
|
||||||
|
|
||||||
# TODO raise this error, if input class is not found
|
# TODO raise this error, if class is not found
|
||||||
# raise NotImplementedError, "Not supported input type "+input_name+" given"
|
# raise NotImplementedError, "Not supported input type "+input_name+" given"
|
||||||
end
|
end
|
||||||
|
|
||||||
def weighting_per_value
|
# Converts CamelCase words into snake_case
|
||||||
require "rubella/weighting/per_value"
|
#
|
||||||
Weighting::PerValue
|
# @param camel_cased_word string Word in CamelCase
|
||||||
end
|
# @return string
|
||||||
|
def underscore(camel_cased_word)
|
||||||
def weighting_per_overall_load
|
camel_cased_word.to_s.gsub(/::/, '/').
|
||||||
require "rubella/weighting/per_overall_load"
|
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
||||||
Weighting::PerOverallLoad
|
tr("-", "_").downcase
|
||||||
end
|
|
||||||
|
|
||||||
def weighting_expotential
|
|
||||||
require "rubella/weighting/expotential"
|
|
||||||
Weighting::Expotential
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue