Class: JSONP3::JSONPathNode
- Inherits:
-
Object
- Object
- JSONP3::JSONPathNode
- Defined in:
- lib/json_p3/node.rb
Overview
A JSON-like value and its location.
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value, location, root) ⇒ JSONPathNode
constructor
A new instance of JSONPathNode.
-
#new_child(value, key) ⇒ Object
Return a new node that is a child of this node.
-
#path ⇒ String
Return the normalized path to this node.
- #to_s ⇒ Object
Constructor Details
#initialize(value, location, root) ⇒ JSONPathNode
Returns a new instance of JSONPathNode.
15 16 17 18 19 |
# File 'lib/json_p3/node.rb', line 15 def initialize(value, location, root) @value = value @location = location @root = root end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
9 10 11 |
# File 'lib/json_p3/node.rb', line 9 def location @location end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
9 10 11 |
# File 'lib/json_p3/node.rb', line 9 def root @root end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
9 10 11 |
# File 'lib/json_p3/node.rb', line 9 def value @value end |
Instance Method Details
#new_child(value, key) ⇒ Object
Return a new node that is a child of this node.
31 32 33 |
# File 'lib/json_p3/node.rb', line 31 def new_child(value, key) JSONPathNode.new(value, [@location, key], @root) end |
#path ⇒ String
Return the normalized path to this node.
23 24 25 26 |
# File 'lib/json_p3/node.rb', line 23 def path segments = @location.flatten.map { |i| i.is_a?(String) ? "[#{JSONP3.canonical_string(i)}]" : "[#{i}]" } "$#{segments.join}" end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/json_p3/node.rb', line 35 def to_s "JSONPathNode(#{value} at #{path})" end |