Skip to content

Instantly share code, notes, and snippets.

@ecmendenhall
Created February 18, 2015 17:40
Show Gist options
  • Save ecmendenhall/c5e82fbdb03978a22d83 to your computer and use it in GitHub Desktop.
Save ecmendenhall/c5e82fbdb03978a22d83 to your computer and use it in GitHub Desktop.
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