Class: DTRCore::Function

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/dtr_core/function.rb

Overview

Represents a state in a DTR file.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#clean_name, #first_match_for_content, #split_strip_select, #strip_and_remove_quotes

Constructor Details

#initialize(name, inputs, output, instructions) ⇒ Function

Returns a new instance of Function.



12
13
14
15
16
17
# File 'lib/dtr_core/function.rb', line 12

def initialize(name, inputs, output, instructions)
  @name = name
  @inputs = inputs
  @output = output
  @instructions = instructions
end

Instance Attribute Details

#inputsObject (readonly)

Returns the value of attribute inputs.



10
11
12
# File 'lib/dtr_core/function.rb', line 10

def inputs
  @inputs
end

#instructionsObject (readonly)

Returns the value of attribute instructions.



10
11
12
# File 'lib/dtr_core/function.rb', line 10

def instructions
  @instructions
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/dtr_core/function.rb', line 10

def name
  @name
end

#outputObject (readonly)

Returns the value of attribute output.



10
11
12
# File 'lib/dtr_core/function.rb', line 10

def output
  @output
end

Class Method Details

.from_definition(definition) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dtr_core/function.rb', line 24

def self.from_definition(definition)
  name = definition[/\s*\[(?<all>[^\]]+)]/, 1]
  inputs = (definition[/Inputs\s*:\s*{\s*(?<inputs>[^}]+)\s*}/, 1])
  # TODO: check output type
  output = definition[/Output:\s*(.+)/, 1]
  instructions = definition[/Instructions:\s*\$(?<inputs>[^\$]+)\$/, 1]

  function_object = new(name, inputs, output, instructions)

  function_object.sanitize

  function_object
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
41
42
43
# File 'lib/dtr_core/function.rb', line 38

def ==(other)
  name == other.name &&
    inputs == other.inputs &&
    output == other.output &&
    instructions == other.instructions
end

#sanitizeObject



19
20
21
22
# File 'lib/dtr_core/function.rb', line 19

def sanitize
  @inputs = format_function_inputs(@inputs)
  @instructions = format_function_instruction(@instructions)
end