Class: TPPlus::Nodes::PosregNode

Inherits:
Object
  • Object
show all
Defined in:
lib/tp_plus/nodes/posreg_node.rb

Constant Summary collapse

COMPONENTS =
{
  "x" => 1,
  "y" => 2,
  "z" => 3,
  "w" => 4,
  "p" => 5,
  "r" => 6,
}
GROUPS =
{
  "gp1" => "GP1",
  "gp2" => "GP2",
  "gp3" => "GP3",
  "gp4" => "GP4",
  "gp5" => "GP5"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ PosregNode

Returns a new instance of PosregNode.



24
25
26
27
# File 'lib/tp_plus/nodes/posreg_node.rb', line 24

def initialize(id)
  @id = id
  @comment = ""
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



22
23
24
# File 'lib/tp_plus/nodes/posreg_node.rb', line 22

def comment
  @comment
end

#idObject (readonly)

Returns the value of attribute id.



23
24
25
# File 'lib/tp_plus/nodes/posreg_node.rb', line 23

def id
  @id
end

Instance Method Details

#comment_stringObject



29
30
31
32
33
# File 'lib/tp_plus/nodes/posreg_node.rb', line 29

def comment_string
  return "" if @comment == ""

  ":#{@comment}"
end

#component(m) ⇒ Object



35
36
37
38
39
# File 'lib/tp_plus/nodes/posreg_node.rb', line 35

def component(m)
  return "" if m == ""

  ",#{COMPONENTS[m]}"
end

#component_groups?(c) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/tp_plus/nodes/posreg_node.rb', line 45

def component_groups?(c)
  [""].concat(GROUPS.keys).include? c
end

#component_valid?(c) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/tp_plus/nodes/posreg_node.rb', line 41

def component_valid?(c)
  [""].concat(COMPONENTS.keys).include? c
end

#eval(context, options = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/tp_plus/nodes/posreg_node.rb', line 53

def eval(context,options={})
  options[:method] ||= ""

  group_string = GROUPS["gp" + options[:group].eval(context).to_s] + ":" if options[:group]

  raise "Invalid component" unless component_valid?(options[:method]) || component_groups?(options[:group])

  "PR[#{group_string}#{@id}#{component(options[:method])}#{comment_string}]"
end

#requires_mixed_logic?(context) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/tp_plus/nodes/posreg_node.rb', line 49

def requires_mixed_logic?(context)
  false
end