Class: EJSONExt::Decoders::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/ejson_ext/decoders/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#keyObject (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

#valueObject



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