Skip to content

Instantly share code, notes, and snippets.

@irmiller22
Created October 11, 2013 16:15
Show Gist options
  • Save irmiller22/6937613 to your computer and use it in GitHub Desktop.
Save irmiller22/6937613 to your computer and use it in GitHub Desktop.
pidgeons.rb
########################
# NYC PIGEON ORGANIZER #
########################
require 'pry'
# Start with the following collected data on NYC pigeons.
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 pigeon_sort(hash)
pigeon_data = {}
hash.each do |characteristics, options|
options.each do |option, names_list|
names_list.each do |bird_name|
pigeon_data[bird_name] ||= {}
case characteristics
when :color
pigeon_data[bird_name][:color] ||= []
pigeon_data[bird_name][:color] << option
when :gender
pigeon_data[bird_name][:gender] ||= {}
pigeon_data[bird_name][:gender] = option
when :lives
pigeon_data[bird_name][:lives] ||= {}
pigeon_data[bird_name][:lives] = option
end
end
end
end
pigeon_data
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment