Class: Mandy::ArraySerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/mandy/support/array_serializer.rb

Constant Summary collapse

SEPERATOR =
'|'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items) ⇒ ArraySerializer

Returns a new instance of ArraySerializer.



8
9
10
# File 'lib/mandy/support/array_serializer.rb', line 8

def initialize(items)
  @items = items || []
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



6
7
8
# File 'lib/mandy/support/array_serializer.rb', line 6

def items
  @items
end

Class Method Details

.from_s(str) ⇒ Object



24
25
26
# File 'lib/mandy/support/array_serializer.rb', line 24

def self.from_s(str)
  str.split(SEPERATOR)
end

.tuples_from_s(str) ⇒ Object



28
29
30
# File 'lib/mandy/support/array_serializer.rb', line 28

def self.tuples_from_s(str)
  from_s(str).map {|s| Tuple.from_s(s) }
end

Instance Method Details

#==(other) ⇒ Object



16
17
18
# File 'lib/mandy/support/array_serializer.rb', line 16

def ==(other)
  (self.class == other.class && self.items == other.items) || (other.is_a?(Array) && self.items == other)
end

#to_aObject



20
21
22
# File 'lib/mandy/support/array_serializer.rb', line 20

def to_a
  @items
end

#to_sObject



12
13
14
# File 'lib/mandy/support/array_serializer.rb', line 12

def to_s
  @items.join(SEPERATOR)
end