Class: Types::RplString

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ RplString

Returns a new instance of RplString.

Raises:

  • (RplTypeError)


7
8
9
10
11
12
# File 'lib/rpl/types/string.rb', line 7

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

  # we systematicalyl trim enclosing "
  @value = value[1..-2]
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.can_parse?(value) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/rpl/types/string.rb', line 18

def self.can_parse?( value )
  value[0] == '"' && value[-1] == '"'
end

Instance Method Details

#==(other) ⇒ Object



22
23
24
25
# File 'lib/rpl/types/string.rb', line 22

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

#to_sObject



14
15
16
# File 'lib/rpl/types/string.rb', line 14

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