Class: JPath::Parser::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/jpath/parser/path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePath

Returns a new instance of Path.



18
19
20
21
22
23
# File 'lib/jpath/parser/path.rb', line 18

def initialize
  @steps = []
  if block_given?
    yield self
  end
end

Instance Attribute Details

#stepsObject (readonly)

Returns the value of attribute steps.



16
17
18
# File 'lib/jpath/parser/path.rb', line 16

def steps
  @steps
end

Instance Method Details

#<<(step) ⇒ Object



41
42
43
44
45
# File 'lib/jpath/parser/path.rb', line 41

def <<(step)
  unless step.is_a?(Self)
    @steps << step
  end
end

#from(item) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jpath/parser/path.rb', line 25

def from(item)
  unless item.is_a?(Item)
    item = Item.new(item)
  end
  list = [Pointer.new]
  steps.each do |step|
    list = list.map { |node|
      step.from(item, node).to_a
    }.flatten
  end
  list = list.map do |pointer|
    item[pointer]
  end
  list
end

#to_sObject



47
48
49
# File 'lib/jpath/parser/path.rb', line 47

def to_s
  @steps.join("/")
end