Class: Cenit::Algorithms::Algorithm

Inherits:
Object
  • Object
show all
Defined in:
lib/cenit/algorithms/algorithm.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#jsonObject (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



33
34
35
# File 'lib/cenit/algorithms/algorithm.rb', line 33

def call_links
  json['call_links'] || []
end

#codeObject



29
30
31
# File 'lib/cenit/algorithms/algorithm.rb', line 29

def code
  json['snippet']['code']
end

#idObject



13
14
15
# File 'lib/cenit/algorithms/algorithm.rb', line 13

def id
  @id ||= json['id'] || object_id.to_s
end


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

Returns:

  • (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

#nameObject



21
22
23
# File 'lib/cenit/algorithms/algorithm.rb', line 21

def name
  json['name']
end

#namespaceObject



17
18
19
# File 'lib/cenit/algorithms/algorithm.rb', line 17

def namespace
  json['namespace']
end

#parametersObject



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