Class: JSONP3::NameSelector
- Defined in:
- lib/json_p3/selector.rb
Overview
The name selector select values from hashes given a key.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Selector
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(env, token, name) ⇒ NameSelector
constructor
A new instance of NameSelector.
- #resolve(node) ⇒ Object
- #singular? ⇒ Boolean
- #to_s ⇒ Object
Methods inherited from Selector
Constructor Details
#initialize(env, token, name) ⇒ NameSelector
Returns a new instance of NameSelector.
37 38 39 40 |
# File 'lib/json_p3/selector.rb', line 37 def initialize(env, token, name) super(env, token) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
35 36 37 |
# File 'lib/json_p3/selector.rb', line 35 def name @name end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
58 59 60 61 62 |
# File 'lib/json_p3/selector.rb', line 58 def ==(other) self.class == other.class && @name == other.name && @token == other.token end |
#hash ⇒ Object
66 67 68 |
# File 'lib/json_p3/selector.rb', line 66 def hash [@name, @token].hash end |
#resolve(node) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/json_p3/selector.rb', line 42 def resolve(node) if node.value.is_a?(Hash) && node.value.key?(@name) [node.new_child(node.value[@name], @name)] else [] end end |
#singular? ⇒ Boolean
50 51 52 |
# File 'lib/json_p3/selector.rb', line 50 def singular? true end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/json_p3/selector.rb', line 54 def to_s JSONP3.canonical_string(@name) end |