Class: AMA::Entity::Mapper::Path::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/ama-entity-mapper/path/segment.rb

Overview

Well, that's quite self-explanatory. Path consists of segments, and here's one.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, prefix = nil, suffix = nil) ⇒ Segment

Returns a new instance of Segment.



14
15
16
17
18
# File 'lib/ama-entity-mapper/path/segment.rb', line 14

def initialize(name, prefix = nil, suffix = nil)
  @name = name
  @prefix = prefix
  @suffix = suffix
end

Instance Attribute Details

#name ⇒ Object (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/ama-entity-mapper/path/segment.rb', line 10

def name
  @name
end

#prefix ⇒ Object (readonly)

Returns the value of attribute prefix.



11
12
13
# File 'lib/ama-entity-mapper/path/segment.rb', line 11

def prefix
  @prefix
end

#suffix ⇒ Object (readonly)

Returns the value of attribute suffix.



12
13
14
# File 'lib/ama-entity-mapper/path/segment.rb', line 12

def suffix
  @suffix
end

Class Method Details

.attribute(name) ⇒ Object



39
40
41
# File 'lib/ama-entity-mapper/path/segment.rb', line 39

def attribute(name)
  new(name, '.')
end

.index(name) ⇒ Object



43
44
45
# File 'lib/ama-entity-mapper/path/segment.rb', line 43

def index(name)
  new(name, '[', ']')
end

Instance Method Details

#==(other) ⇒ Object



34
35
36
# File 'lib/ama-entity-mapper/path/segment.rb', line 34

def ==(other)
  eql?(other)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/ama-entity-mapper/path/segment.rb', line 28

def eql?(other)
  return false unless other.is_a?(self.class)
  @name == other.name && @prefix == other.prefix &&
    @suffix == other.suffix
end

#hash ⇒ Object



24
25
26
# File 'lib/ama-entity-mapper/path/segment.rb', line 24

def hash
  @name.hash ^ @prefix.hash ^ @suffix.hash
end

#to_s ⇒ Object



20
21
22
# File 'lib/ama-entity-mapper/path/segment.rb', line 20

def to_s
  "#{@prefix}#{@name}#{@suffix}"
end