Module: GoogleSpreadsheet2yml

Defined in:
lib/google_spreadsheet2yml.rb,
lib/google_spreadsheet2yml/railtie.rb,
lib/google_spreadsheet2yml/version.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

VERSION =
"0.1.6"

Class Method Summary collapse

Class Method Details

.create_yaml(hash) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/google_spreadsheet2yml.rb', line 12

def self.create_yaml(hash)
  @result = Hash.new
  merger = proc { |key,v1,v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
  hash.keys.each do |key|
    @result = @result.merge(hash_from_array(key, key.split('.'), hash), &merger)
  end
  @result.to_yaml
end

.hash_from_array(key, arr, main_hash) ⇒ Object



6
7
8
9
10
# File 'lib/google_spreadsheet2yml.rb', line 6

def self.hash_from_array(key, arr, main_hash)
  current_first = arr.delete_at(0)
  return { current_first => hash_from_array(key, arr, main_hash) } if arr.size > 0
  return { current_first => main_hash[key] }                       if arr.size == 0
end