-
-
Save imcodingideas/12980a8f640697baa4f06ebc7e1c472e to your computer and use it in GitHub Desktop.
This file contains 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
#ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15] | |
class FoodGroup | |
def initialize(food) | |
@food = food | |
end | |
MAPPINGS = { | |
"grain" => ['Rice', 'Trigo', 'Avena', 'Barley', 'Flour'], | |
"vegetable" => ['Carrot', 'corn' 'Corn', 'Pumpkin', 'Papa'], | |
"fruit" => ['Apple', 'Mango', 'Strawberry', 'Peaches', 'Pineapple'], | |
"meat" => ['Res', 'Chicken', 'Salmon', 'Fish', 'Pig'], | |
"dairy" => ['Milk', 'Yogurt', 'Cheese', 'Cream'] | |
} | |
def food_group | |
food.each do |lookup| | |
MAPPINGS.fetch(lookup, "food not found") | |
end | |
end | |
end | |
food_group = FoodGroup.new('a') | |
# Driver code | |
p food_group('Cream') == "dairy" | |
p food_group('Beef') == "meat" | |
p food_group('Pineapple') == "fruit" | |
p food_group('Cane') == "food not found" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment