Created
October 11, 2013 16:15
-
-
Save irmiller22/6937613 to your computer and use it in GitHub Desktop.
pidgeons.rb
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
| ######################## | |
| # 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