Skip to content

Instantly share code, notes, and snippets.

@imcodingideas
Last active August 12, 2016 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imcodingideas/12980a8f640697baa4f06ebc7e1c472e to your computer and use it in GitHub Desktop.
Save imcodingideas/12980a8f640697baa4f06ebc7e1c472e to your computer and use it in GitHub Desktop.
#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