Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/outline.rb

Instance Method Summary collapse

Instance Method Details

#to_outlineObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/outline.rb', line 5

def to_outline
  convert_data = Proc.new do |data|
    data.each_with_object({}) do |(key, value), memo|
      if value.respond_to?(:to_hash) || value.respond_to?(:to_h)
        value = value.respond_to?(:to_hash) ? value.to_hash : value.to_h
        value = value.to_outline
      end
      
      memo[key] = value
    end
  end
  
  data = convert_data[ self ]
  
  Outline.new(data: data)
end