Class: JPath::Parser::Path
- Inherits:
-
Object
- Object
- JPath::Parser::Path
- Defined in:
- lib/jpath/parser/path.rb
Instance Attribute Summary collapse
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
Instance Method Summary collapse
- #<<(step) ⇒ Object
- #from(item) ⇒ Object
-
#initialize ⇒ Path
constructor
A new instance of Path.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Path
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
#steps ⇒ Object (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_s ⇒ Object
47 48 49 |
# File 'lib/jpath/parser/path.rb', line 47 def to_s @steps.join("/") end |