Created
December 28, 2010 17:26
-
-
Save adamgamble/757435 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Quiz | |
def initialize | |
@f = {} | |
@f['en.steps.foo'] = 'bar' | |
@f['en.steps.bar'] = 'wiggity' | |
@f['en.boogie.foo'] = 'liar' | |
@f['en.boogie.baz.noodles'] = 'potatosack' | |
@new_hash = {} | |
end | |
def run | |
main_hash = {} | |
@f.each_pair do |k,v| | |
key_array = k.split(".") | |
key_array.each_with_index do |key,i| | |
case i | |
when 0 | |
main_hash[key] = {} unless main_hash.keys.include?(key) | |
when 1 | |
main_hash[key_array.first][key] = {} unless main_hash[main_hash.keys.first].keys.include?(key) | |
when 2 | |
main_hash[key_array.first][key_array[i - 1]][key] = v if !(key_array.count > (i + 1)) | |
main_hash[key_array.first][key_array[i - 1]][key] = {} if (key_array.count > (i + 1)) | |
when 3 | |
main_hash[key_array.first][key_array.second][key_array.third][key] = v | |
end | |
end | |
end | |
main_hash | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment