Class: DailyPlan

Inherits:
Object
  • Object
show all
Defined in:
lib/daily_plan.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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,menu,budget)
    @user = user
    @menu = menu
    @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

#budgetObject

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_planObject



32
33
34
35
36
37
38
# File 'lib/daily_plan.rb', line 32

def generate_meal_plan
    return {
        :breakfast => get_user_menu(get_price(@BREAKFAST_PERCENT), @BREAKFAST_IDENTIFIER).sample,
        :lunch => get_user_menu(get_price(@LUNCH_PERCENT), @LUNCH_IDENTIFIER).sample,
        :dinner => get_user_menu(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 get_user_menu(price, menu_category_id)
    return @menu.select {|menu| menu["price"] <= price && menu["menu_category_id"]  == menu_category_id  && menu["menu_type_id"] == @user.menu_type_id }
end