Class: Types::RplName

Inherits:
Object
  • Object
show all
Defined in:
lib/rpl/types/name.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ RplName

Returns a new instance of RplName.

Raises:

  • (RplTypeError)


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rpl/types/name.rb', line 8

def initialize( value )
  raise RplTypeError unless self.class.can_parse?( value )

  # we systematicalyl trim enclosing '
  @not_to_evaluate = value[0] == "'"
  @value = if value[0] == "'" && value[-1] == "'"
             value[1..-2]
           else
             value
           end
end

Instance Attribute Details

#not_to_evaluateObject

Returns the value of attribute not_to_evaluate.



5
6
7
# File 'lib/rpl/types/name.rb', line 5

def not_to_evaluate
  @not_to_evaluate
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/rpl/types/name.rb', line 5

def value
  @value
end

Class Method Details

.can_parse?(value) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
# File 'lib/rpl/types/name.rb', line 24

def self.can_parse?( value )
  ( value.length > 2 and value[0] == "'" and value[-1] == "'" ) or
    ( value != "''" and !value.match?(/^[0-9']+$/) and
      # it's not any other type
      [RplBoolean, RplList, RplProgram, RplString, RplNumeric].reduce( true ) { |memo, type_class| memo && !type_class.can_parse?( value ) } )
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
34
# File 'lib/rpl/types/name.rb', line 31

def ==( other )
  other.class == RplName and
    other.value == value
end

#to_sObject



20
21
22
# File 'lib/rpl/types/name.rb', line 20

def to_s
  "'#{@value}'"
end