Class: Types::RplList
- Inherits:
-
Object
- Object
- Types::RplList
- Defined in:
- lib/rpl/types/list.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(value) ⇒ RplList
constructor
A new instance of RplList.
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ RplList
Returns a new instance of RplList.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rpl/types/list.rb', line 9 def initialize( value ) raise RplTypeError unless self.class.can_parse?( value ) @value = if value.instance_of?( Array ) value else # we systematically trim enclosing { } Parser.parse( value[2..-3] ) end end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
7 8 9 |
# File 'lib/rpl/types/list.rb', line 7 def value @value end |
Class Method Details
.can_parse?(value) ⇒ Boolean
24 25 26 27 28 |
# File 'lib/rpl/types/list.rb', line 24 def self.can_parse?( value ) value.instance_of?( Array ) || ( value[0..1] == '{ ' && value[-2..] == ' }' ) end |
Instance Method Details
#==(other) ⇒ Object
30 31 32 33 |
# File 'lib/rpl/types/list.rb', line 30 def ==( other ) other.class == RplList && other.value == value end |
#to_s ⇒ Object
20 21 22 |
# File 'lib/rpl/types/list.rb', line 20 def to_s "{ #{@value.map(&:to_s).join(' ')} }" end |