Skip to content

Instantly share code, notes, and snippets.

@blake41
Created July 30, 2015 22:04
Show Gist options
  • Save blake41/c6a1543f2a76b5f1baba to your computer and use it in GitHub Desktop.
Save blake41/c6a1543f2a76b5f1baba to your computer and use it in GitHub Desktop.
require 'pry'
require 'pry-nav'
require 'ap'
pigeon_data = {
:color => {
:purple => ["Theo", "Peter Jr.", "Lucky"],
:grey => ["Theo", "Peter Jr.", "Ms. K"],
:white => ["Queenie", "Andrew", "Ms. K", "Alex"],
:brown => ["Queenie", "Alex"]
},
:gender => {
:male => ["Alex", "Theo", "Peter Jr.", "Andrew", "Lucky"],
:female => ["Queenie", "Ms. K"]
},
:lives => {
"Subway" => ["Theo", "Queenie"],
"Central Park" => ["Alex", "Ms. K", "Lucky"],
"Library" => ["Peter Jr."],
"City Hall" => ["Andrew"]
}
}
def nyc_pigeon_organizer(data)
pigeon_hash = {}
data.each_pair do |attribute, values|
# attribute like :color
# values = {
# :purple => ["Theo", "Peter Jr.", "Lucky"],
# :grey => ["Theo", "Peter Jr.", "Ms. K"],
# :white => ["Queenie", "Andrew", "Ms. K", "Alex"],
# :brown => ["Queenie", "Alex"]
# }
values.each_pair do |specific_values, pigeons|
# specific_values like :purple
# pigeons like ["Theo", "Peter Jr.", "Lucky"]
pigeons.each do |pigeon|
# pigeon like "theo"
# i
if pigeon_hash[pigeon].nil?
# binding.pry
pigeon_hash[pigeon] = {}
end
if pigeon_hash[pigeon][attribute]
pigeon_hash[pigeon][attribute] << specific_values.to_s
else
pigeon_hash[pigeon][attribute] = []
pigeon_hash[pigeon][attribute] << specific_values.to_s
end
# either the pigeon exists
# it does not exist
end
end
end
# binding.pry
pigeon_hash
end
# start
# nyc_pigeon_organizer(pigeon_data)
pigeon_list = {
"Theo" => {
:color => ["purple", "grey"],
:gender => ["male"],
:lives => ["Subway"]
},
"Peter Jr." => {
:color => ["purple", "grey"],
:gender => ["male"],
:lives => ["Library"]
},
"Lucky" => {
:color => ["purple"],
:gender => ["male"],
:lives => ["Central Park"]
},
"Ms. K" => {
:color => ["grey", "white"],
:gender => ["female"],
:lives => ["Central Park"]
},
"Queenie" => {
:color => ["white", "brown"],
:gender => ["female"],
:lives => ["Subway"]
},
"Andrew" => {
:color => ["white"],
:gender => ["male"],
:lives => ["City Hall"]
},
"Alex" => {
:color => ["white", "brown"],
:gender => ["male"],
:lives => ["Central Park"]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment