Class: JSONP3::Path::Node
- Inherits:
-
Object
- Object
- JSONP3::Path::Node
- Defined in:
- lib/json_p3/path/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) ⇒ Node
constructor
A new instance of Node.
-
#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
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
10 11 12 |
# File 'lib/json_p3/path/node.rb', line 10 def location @location end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
10 11 12 |
# File 'lib/json_p3/path/node.rb', line 10 def root @root end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
10 11 12 |
# File 'lib/json_p3/path/node.rb', line 10 def value @value end |
Instance Method Details
#new_child(value, key) ⇒ Object
Return a new node that is a child of this node.
34 35 36 |
# File 'lib/json_p3/path/node.rb', line 34 def new_child(value, key) Node.new(value, [@location, key], @root) end |
#path ⇒ String
Return the normalized path to this node.
24 25 26 27 28 29 |
# File 'lib/json_p3/path/node.rb', line 24 def path segments = @location.flatten.map do |i| i.is_a?(String) ? "[#{JSONP3::Path.canonical_string(i)}]" : "[#{i}]" end "$#{segments.join}" end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/json_p3/path/node.rb', line 38 def to_s "Node(#{value} at #{path})" end |