Class: Mandy::Tuple

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

Constant Summary collapse

SEPERATOR =
','

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value, name_accessor = nil, value_accessor = nil) ⇒ Tuple

Returns a new instance of Tuple.



8
9
10
11
12
# File 'lib/mandy/support/tuple.rb', line 8

def initialize(name, value, name_accessor = nil, value_accessor = nil)
  @name, @value = name, value
  alias_accessor(name_accessor, :name) unless name_accessor.nil?
  alias_accessor(value_accessor, :value) unless value_accessor.nil?
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.from_s(str) ⇒ Object



18
19
20
21
22
# File 'lib/mandy/support/tuple.rb', line 18

def self.from_s(str)
  parts = str.split(SEPERATOR)
  raise "Can't create tuple from #{str.inspect}. Format should be 'A#{SEPERATOR}B'" unless parts.size==2
  new(*parts)
end

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  return false unless self.class == other.class
  self.name == other.name && self.value == other.value
end

#inspectObject



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

def inspect
  %(<Tuple #{self.to_s}>)
end

#to_sObject



14
15
16
# File 'lib/mandy/support/tuple.rb', line 14

def to_s
  %(#{@name}#{SEPERATOR}#{@value})
end