summaryrefslogtreecommitdiff
path: root/lib/algorithm.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/algorithm.rb')
-rw-r--r--lib/algorithm.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/algorithm.rb b/lib/algorithm.rb
index 0e227d6..113f847 100644
--- a/lib/algorithm.rb
+++ b/lib/algorithm.rb
@@ -2,10 +2,18 @@ module OpenTox
module Algorithm
- def self.run algorithm, object, parameters={}
+ # Generic method to execute algorithms
+ # Algorithms should:
+ # - accept a Compound, an Array of Compounds or a Dataset as first argument
+ # - optional parameters as second argument
+ # - return an object corresponding to the input type as result (eg. Compound -> value, Array of Compounds -> Array of values, Dataset -> Dataset with values
+ # @param [OpenTox::Compound,Array,OpenTox::Dataset] Input object
+ # @param [Hash] Algorithm parameters
+ # @return Algorithm result
+ def self.run algorithm, object, parameters=nil
bad_request_error "Cannot run '#{algorithm}' algorithm. Please provide an OpenTox::Algorithm." unless algorithm =~ /^OpenTox::Algorithm/
klass,method = algorithm.split('.')
- parameters.empty? ? Object.const_get(klass).send(method,object) : Object.const_get(klass).send(method,object, parameters)
+ parameters.nil? ? Object.const_get(klass).send(method,object) : Object.const_get(klass).send(method,object, parameters)
end
end