Class: EJSONExt::Decoders::Node
- Inherits:
-
Object
- Object
- EJSONExt::Decoders::Node
- Defined in:
- lib/ejson_ext/decoders/node.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #compile(parent_node, hash) ⇒ Object
-
#initialize(key, value) ⇒ Node
constructor
A new instance of Node.
- #value ⇒ Object
Constructor Details
#initialize(key, value) ⇒ Node
Returns a new instance of Node.
6 7 8 9 |
# File 'lib/ejson_ext/decoders/node.rb', line 6 def initialize(key, value) @key = key @value = value end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
4 5 6 |
# File 'lib/ejson_ext/decoders/node.rb', line 4 def key @key end |
Instance Method Details
#compile(parent_node, hash) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/ejson_ext/decoders/node.rb', line 19 def compile(parent_node, hash) if parent_node.key && @value.is_a?(Integer) Time.at(value / 1_000.0) elsif key == '$escape' value else hash.merge @key => value end end |
#value ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/ejson_ext/decoders/node.rb', line 11 def value if @value.is_a?(Hash) @value.each.inject({}) { |hash, args| subnode(hash, args) } else @value end end |