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



6
7
8
9
10
# File 'lib/zapata/primitive/hash.rb', line 6

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

#to_aObject



12
13
14
# File 'lib/zapata/primitive/hash.rb', line 12

def to_a
  value.to_a.flatten
end

#to_rawObject



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

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