Created
February 18, 2015 17:40
-
-
Save ecmendenhall/c5e82fbdb03978a22d83 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 SpaceJam | |
def index(item) | |
if item.is_a?(Hash) | |
key = item['name'] | |
items[key] = item | |
increment_name(key) | |
if item['children'] | |
item['children'].each do |child| | |
index(child) | |
end | |
end | |
end | |
end | |
def populate_hash_table | |
METADATA_STRUCTURE['children'].each do |child| | |
index(child) | |
end | |
end | |
def increment_name(name) | |
count = names[name] | |
if count.nil? | |
names[name] = 1 | |
else | |
names[name] = count + 1 | |
end | |
end | |
def names | |
@names ||= {} | |
end | |
def items | |
@items ||= {} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment