Class: Zapata::Primitive::Hash

Inherits:
Base
  • Object
show all
Defined in:
lib/zapata/primitive/hash.rb

Instance Attribute Summary

Attributes inherited from Base

#code, #type

Instance Method Summary collapse

Methods inherited from Base

#dive_deeper, #initialize, #name, #return_with_missing_as_super, #return_with_super_as_missing

Constructor Details

This class inherits a constructor from Zapata::Primitive::Base

Instance Method Details

#nodeObject



4
5
6
7
8
# File 'lib/zapata/primitive/hash.rb', line 4

def node
  body = @code
  type = @code.type
  OpenStruct.new(type: type, body: body)
end

#to_aObject



10
11
12
# File 'lib/zapata/primitive/hash.rb', line 10

def to_a
  value.to_a.flatten
end

#to_rawObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/zapata/primitive/hash.rb', line 14

def to_raw
  result = {}

  node.body.to_a.each do |pair|
    key_node, value_node = pair.to_a
    key = Diver.dive(key_node).to_raw
    value = Diver.dive(value_node).to_raw
    result[key] = value
  end

  Raw.new(:hash, result)
end