Class: Namarara::VarValue

Inherits:
TreeValue show all
Defined in:
lib/namarara/parser.rb

Instance Attribute Summary collapse

Attributes inherited from TreeValue

#value

Instance Method Summary collapse

Constructor Details

#initialize(str, value) ⇒ VarValue

Returns a new instance of VarValue.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/namarara/parser.rb', line 21

def initialize(str, value)
  @errors = []
  @name = str
  @value = value
  @value = true if value =~ /^true$/i
  @value = false if value =~ /^false$/i
  return unless @value.nil?

  @errors << Errors::VarNotDefined.new(
    message: "No value for #{@name}",
    var: @name
  )
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



19
20
21
# File 'lib/namarara/parser.rb', line 19

def errors
  @errors
end

Instance Method Details

#computeObject



35
36
37
# File 'lib/namarara/parser.rb', line 35

def compute
  @value
end

#to_sObject



39
40
41
# File 'lib/namarara/parser.rb', line 39

def to_s
  "var:#{@name}<-(#{@value})"
end