class AMA::Entity::Mapper::Path

Wrapper for simple array. Helps to understand where exactly processing is taking place.

Attributes

segments[R]

Public Class Methods

new(stack = []) click to toggle source
# File lib/ama-entity-mapper/path.rb, line 13
def initialize(stack = [])
  @segments = stack
end

Public Instance Methods

attribute(name) click to toggle source

@param [String, Symbol] name @return [AMA::Entity::Mapper::Path]

# File lib/ama-entity-mapper/path.rb, line 29
def attribute(name)
  push(Segment.attribute(name))
end
current() click to toggle source

@return [AMA::Entity::Mapper::Path::Segment]

# File lib/ama-entity-mapper/path.rb, line 49
def current
  @segments.last
end
each() { |item| ... } click to toggle source
# File lib/ama-entity-mapper/path.rb, line 53
def each
  @segments.each do |item|
    yield(item)
  end
end
empty?() click to toggle source
# File lib/ama-entity-mapper/path.rb, line 17
def empty?
  @segments.empty?
end
index(name) click to toggle source

@param [String, Symbol, Integer] name @return [AMA::Entity::Mapper::Path]

# File lib/ama-entity-mapper/path.rb, line 23
def index(name)
  push(Segment.index(name))
end
merge(path) click to toggle source

@param [AMA::Entity::Mapper::Path] path @return [AMA::Entity::Mapper::Path]

# File lib/ama-entity-mapper/path.rb, line 67
def merge(path)
  push(*path.segments)
end
pop() click to toggle source

@return [AMA::Entity::Mapper::Path]

# File lib/ama-entity-mapper/path.rb, line 44
def pop
  self.class.new(@segments[0..-2])
end
push(*segments) click to toggle source

@param [Array<AMA::Entity::Mapper::Path::Segment>] segments @return [AMA::Entity::Mapper::Path]

# File lib/ama-entity-mapper/path.rb, line 35
def push(*segments)
  segments = segments.map do |segment|
    next segment if segment.is_a?(Segment)
    Segment.attribute(segment)
  end
  self.class.new(@segments + segments)
end
reduce(carrier) { |inner_carrier, item| ... } click to toggle source
# File lib/ama-entity-mapper/path.rb, line 59
def reduce(carrier)
  @segments.reduce(carrier) do |inner_carrier, item|
    yield(inner_carrier, item)
  end
end
size() click to toggle source
# File lib/ama-entity-mapper/path.rb, line 71
def size
  @segments.size
end
to_a() click to toggle source

@return [Array<AMA::Entity::Mapper::Path::Segment>]

# File lib/ama-entity-mapper/path.rb, line 80
def to_a
  @segments.clone
end
to_s() click to toggle source

@return [String]

# File lib/ama-entity-mapper/path.rb, line 85
def to_s
  "$#{@segments.join}"
end