Class: MediServ::API::Encoder

Inherits:
Object
  • Object
show all
Defined in:
lib/mediserv/api/encoder.rb

Instance Method Summary collapse

Instance Method Details

#build_tree(node, h) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mediserv/api/encoder.rb', line 9

def build_tree(node, h)
  h.each do |k, v|
    case v
    when Hash
      child = Node.new(name: [node.name, k].compact.join('.'))
      node.children << child
      build_tree(child, v)
    else
      node.attributes[k] = v
    end
  end
  node
end

#encode(h) ⇒ Object



5
6
7
# File 'lib/mediserv/api/encoder.rb', line 5

def encode(h)
  build_tree(Node.new, h).to_ini
end