Class: DailyPlan
- Inherits:
-
Object
- Object
- DailyPlan
- Defined in:
- lib/daily_plan.rb
Instance Attribute Summary collapse
-
#budget ⇒ Object
Returns the value of attribute budget.
Instance Method Summary collapse
- #generate_meal_plan ⇒ Object
- #get_price(percent) ⇒ Object
- #get_user_menu(price, menu_category_id) ⇒ Object
-
#initialize(user, menu, budget) ⇒ DailyPlan
constructor
A new instance of DailyPlan.
Constructor Details
#initialize(user, menu, budget) ⇒ DailyPlan
Returns a new instance of DailyPlan.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/daily_plan.rb', line 5 def initialize(user,,budget) @user = user = @budget = budget.amount @BREAKFAST_PERCENT = 25 @LUNCH_PERCENT = 40 @DINNER_PERCENT = 35 @BREAKFAST_IDENTIFIER = 1 @LUNCH_IDENTIFIER = 2 @DINNER_IDENTIFIER = 3 @VEGAN = 1 @VEGETERIAN = 2 @NONVEGAN = 3 end |
Instance Attribute Details
#budget ⇒ Object
Returns the value of attribute budget.
3 4 5 |
# File 'lib/daily_plan.rb', line 3 def budget @budget end |
Instance Method Details
#generate_meal_plan ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/daily_plan.rb', line 32 def generate_meal_plan return { :breakfast => (get_price(@BREAKFAST_PERCENT), @BREAKFAST_IDENTIFIER).sample, :lunch => (get_price(@LUNCH_PERCENT), @LUNCH_IDENTIFIER).sample, :dinner => (get_price(@DINNER_PERCENT), @DINNER_IDENTIFIER).sample } end |
#get_price(percent) ⇒ Object
24 25 26 |
# File 'lib/daily_plan.rb', line 24 def get_price(percent) return (budget * percent) / 100 end |
#get_user_menu(price, menu_category_id) ⇒ Object
28 29 30 |
# File 'lib/daily_plan.rb', line 28 def (price, ) return .select {|| ["price"] <= price && ["menu_category_id"] == && ["menu_type_id"] == @user. } end |