Class: Types::RplName
- Inherits:
-
Object
- Object
- Types::RplName
- Defined in:
- lib/rpl/types/name.rb
Instance Attribute Summary collapse
-
#not_to_evaluate ⇒ Object
Returns the value of attribute not_to_evaluate.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(value) ⇒ RplName
constructor
A new instance of RplName.
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ RplName
Returns a new instance of RplName.
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_evaluate ⇒ Object
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 |
#value ⇒ Object
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
24 25 26 27 28 29 |
# File 'lib/rpl/types/name.rb', line 24 def self.can_parse?( value ) ( value.length > 2 && value[0] == "'" && value[-1] == "'" ) || ( value != "''" && !value.match?(/^[0-9']+$/) && # 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 && other.value == value end |
#to_s ⇒ Object
20 21 22 |
# File 'lib/rpl/types/name.rb', line 20 def to_s "'#{@value}'" end |