Class: Cenit::Algorithms::Algorithm
- Inherits:
-
Object
- Object
- Cenit::Algorithms::Algorithm
- Defined in:
- lib/cenit/algorithms/algorithm.rb
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Instance Method Summary collapse
- #call_links ⇒ Object
- #code ⇒ Object
- #id ⇒ Object
-
#initialize(json) ⇒ Algorithm
constructor
A new instance of Algorithm.
- #link(name) ⇒ Object
- #link?(name) ⇒ Boolean
- #name ⇒ Object
- #namespace ⇒ Object
- #parameters ⇒ Object
- #run(*args) ⇒ Object
Constructor Details
#initialize(json) ⇒ Algorithm
Returns a new instance of Algorithm.
9 10 11 |
# File 'lib/cenit/algorithms/algorithm.rb', line 9 def initialize(json) @json = json end |
Instance Attribute Details
#json ⇒ Object (readonly)
Returns the value of attribute json.
7 8 9 |
# File 'lib/cenit/algorithms/algorithm.rb', line 7 def json @json end |
Instance Method Details
#call_links ⇒ Object
33 34 35 |
# File 'lib/cenit/algorithms/algorithm.rb', line 33 def call_links json['call_links'] || [] end |
#code ⇒ Object
29 30 31 |
# File 'lib/cenit/algorithms/algorithm.rb', line 29 def code json['snippet']['code'] end |
#id ⇒ Object
13 14 15 |
# File 'lib/cenit/algorithms/algorithm.rb', line 13 def id @id ||= json['id'] || object_id.to_s end |
#link(name) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cenit/algorithms/algorithm.rb', line 42 def link(name) name = name.to_s call_link = call_links.detect { |call_link| call_link['name'] == name } if call_link Algorithms.find(id: call_link['link']['id'], namespace: call_link['link']['namespace'], name: call_link['link']['name']) else fail "Error linking #{name}" end end |
#link?(name) ⇒ Boolean
37 38 39 40 |
# File 'lib/cenit/algorithms/algorithm.rb', line 37 def link?(name) name = name.to_s call_links.any? { |call_link| call_link['name'] == name } end |
#name ⇒ Object
21 22 23 |
# File 'lib/cenit/algorithms/algorithm.rb', line 21 def name json['name'] end |
#namespace ⇒ Object
17 18 19 |
# File 'lib/cenit/algorithms/algorithm.rb', line 17 def namespace json['namespace'] end |
#parameters ⇒ Object
25 26 27 |
# File 'lib/cenit/algorithms/algorithm.rb', line 25 def parameters json['parameters'] || [] end |
#run(*args) ⇒ Object
54 55 56 |
# File 'lib/cenit/algorithms/algorithm.rb', line 54 def run(*args) Interpreter.run(self, *args) end |