meal_budget_planner 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/daily_plan.rb +38 -14
- data/lib/daily_plan_decorator.rb +11 -0
- data/lib/meal_planner.rb +66 -0
- data/lib/mock/menu.rb +168 -168
- data/lib/model/user.rb +8 -8
- data/lib/model/user_budget.rb +13 -13
- data/lib/monthly_plan.rb +19 -18
- data/lib/weekly_plan.rb +19 -18
- metadata +4 -4
- data/lib/meal_plan.rb +0 -28
- data/lib/plan.rb +0 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e13998a1e670eeeb817612ca83eef5c892d23877549c534c39c969e9aa0518e1
|
|
4
|
+
data.tar.gz: c67ba703fdccdafed042b8b2f7b46ac9587866c87637d58ce755f6d7f27688ec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d786a20daeca3c62c843522a9efccb7ad3715206772582c40fdf026a7fb52401f6e531f7dbe95653cf3403921d2f034f84a4ebd92687aec7fc955e0e4a1470a0
|
|
7
|
+
data.tar.gz: d88dab13da744fa4429531aac6f3ca4399514630c9b9d0a43355caa720b0adb40f007f8c5a3c25aa289b4f97c73e7d14474e23d6ff5f6365384a09bf6e4844f4
|
data/lib/daily_plan.rb
CHANGED
|
@@ -1,15 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def
|
|
6
|
-
@user =
|
|
7
|
-
@menu =
|
|
8
|
-
@budget =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
class DailyPlan
|
|
2
|
+
|
|
3
|
+
attr_accessor :budget
|
|
4
|
+
|
|
5
|
+
def initialize(user,menu,budget)
|
|
6
|
+
@user = user
|
|
7
|
+
@menu = menu
|
|
8
|
+
@budget = budget.amount
|
|
9
|
+
@BREAKFAST_PERCENT = 25
|
|
10
|
+
@LUNCH_PERCENT = 40
|
|
11
|
+
@DINNER_PERCENT = 35
|
|
12
|
+
@BREAKFAST_IDENTIFIER = 1
|
|
13
|
+
@LUNCH_IDENTIFIER = 2
|
|
14
|
+
@DINNER_IDENTIFIER = 3
|
|
15
|
+
@VEGAN = 1
|
|
16
|
+
@VEGETERIAN = 2
|
|
17
|
+
@NONVEGAN = 3
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def budget
|
|
21
|
+
@budget
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def get_price(percent)
|
|
25
|
+
return (budget * percent) / 100
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def get_user_menu(price, menu_category_id)
|
|
29
|
+
return @menu.select {|menu| menu["price"] <= price && menu["menu_category_id"] == menu_category_id && menu["menu_type_id"] == @user.menu_type_id }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def generate_meal_plan
|
|
33
|
+
return {
|
|
34
|
+
:breakfast => get_user_menu(get_price(@BREAKFAST_PERCENT), @BREAKFAST_IDENTIFIER).sample,
|
|
35
|
+
:lunch => get_user_menu(get_price(@LUNCH_PERCENT), @LUNCH_IDENTIFIER).sample,
|
|
36
|
+
:dinner => get_user_menu(get_price(@DINNER_PERCENT), @DINNER_IDENTIFIER).sample
|
|
37
|
+
}
|
|
38
|
+
end
|
|
15
39
|
end
|
data/lib/meal_planner.rb
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
class MealPlanner
|
|
2
|
+
#weights to break down user budget
|
|
3
|
+
|
|
4
|
+
def initialize(user,menu,budget)
|
|
5
|
+
@user = user
|
|
6
|
+
@menu = menu
|
|
7
|
+
@budget = budget.amount
|
|
8
|
+
@BREAKFAST_PERCENT = 25
|
|
9
|
+
@LUNCH_PERCENT = 40
|
|
10
|
+
@DINNER_PERCENT = 35
|
|
11
|
+
@BREAKFAST_IDENTIFIER = 1
|
|
12
|
+
@LUNCH_IDENTIFIER = 2
|
|
13
|
+
@DINNER_IDENTIFIER = 3
|
|
14
|
+
@VEGAN = 1
|
|
15
|
+
@VEGETERIAN = 2
|
|
16
|
+
@NONE = 3
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# getting meal plan
|
|
20
|
+
def generate_meal_plan
|
|
21
|
+
if budget.budget_type == "daily"
|
|
22
|
+
return generate_daily_meal_plan
|
|
23
|
+
elsif budget.budget_type == "weekly"
|
|
24
|
+
return generate_weekly_meal_plan
|
|
25
|
+
elsif budget.budget_type == "monthly"
|
|
26
|
+
return generate_monthly_meal_plan
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# calculation for breakfast
|
|
31
|
+
def get_price(percent)
|
|
32
|
+
return (@budget * percent) / 100
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# breakfast filtering
|
|
36
|
+
def get_user_menu(price, menu_category_id)
|
|
37
|
+
return @menu.select {|menu| menu["price"] <= price && menu["menu_category_id"] == menu_category_id && menu["menu_type_id"] == @user.menu_type_id }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
#generating meal plans for monthly weekly and daily
|
|
41
|
+
def generate_daily_meal_plan
|
|
42
|
+
return {
|
|
43
|
+
:breakfast => get_user_menu(get_price(@BREAKFAST_PERCENT), @BREAKFAST_IDENTIFIER).sample,
|
|
44
|
+
:lunch => get_user_menu(get_price(@LUNCH_PERCENT), @LUNCH_IDENTIFIER).sample,
|
|
45
|
+
:dinner => get_user_menu(get_price(@DINNER_PERCENT), @DINNER_IDENTIFIER).sample
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def generate_weekly_meal_plan
|
|
50
|
+
@budget = @budget / 7 # get daily budget
|
|
51
|
+
meal_plan = Array.new
|
|
52
|
+
7.times do |n|
|
|
53
|
+
meal_plan.push(generate_daily_meal_plan)
|
|
54
|
+
end
|
|
55
|
+
return meal_plan
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def generate_monthly_meal_plan
|
|
59
|
+
@budget = @budget / 31 # from daily budget
|
|
60
|
+
meal_plan = Array.new
|
|
61
|
+
31.times do |n|
|
|
62
|
+
meal_plan.push(generate_daily_meal_plan)
|
|
63
|
+
end
|
|
64
|
+
return meal_plan
|
|
65
|
+
end
|
|
66
|
+
end
|
data/lib/mock/menu.rb
CHANGED
|
@@ -1,169 +1,169 @@
|
|
|
1
|
-
require 'faker'
|
|
2
|
-
class Menu
|
|
3
|
-
def self.get_menu
|
|
4
|
-
return [
|
|
5
|
-
{
|
|
6
|
-
"name" => Faker::Food.dish,
|
|
7
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
8
|
-
"menu_category_id" => 1,
|
|
9
|
-
"menu_type_id" => 1
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
"name" => Faker::Food.dish,
|
|
13
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
14
|
-
"menu_category_id" => 1,
|
|
15
|
-
"menu_type_id" => 1
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"name" => Faker::Food.dish,
|
|
19
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
20
|
-
"menu_category_id" => 1,
|
|
21
|
-
"menu_type_id" => 1
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"name" => Faker::Food.dish,
|
|
25
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
26
|
-
"menu_category_id" => 1,
|
|
27
|
-
"menu_type_id" => 2
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"name" => Faker::Food.dish,
|
|
31
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
32
|
-
"menu_category_id" => 1,
|
|
33
|
-
"menu_type_id" => 2
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
"name" => Faker::Food.dish,
|
|
37
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
38
|
-
"menu_category_id" => 1,
|
|
39
|
-
"menu_type_id" => 2
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"name" => Faker::Food.dish,
|
|
43
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
44
|
-
"menu_category_id" => 1,
|
|
45
|
-
"menu_type_id" => 3
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
"name" => Faker::Food.dish,
|
|
49
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
50
|
-
"menu_category_id" => 1,
|
|
51
|
-
"menu_type_id" => 3
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
"name" => Faker::Food.dish,
|
|
55
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
56
|
-
"menu_category_id" => 1,
|
|
57
|
-
"menu_type_id" => 3
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
"name" => Faker::Food.dish,
|
|
61
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
62
|
-
"menu_category_id" => 2,
|
|
63
|
-
"menu_type_id" => 1
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
"name" => Faker::Food.dish,
|
|
67
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
68
|
-
"menu_category_id" => 2,
|
|
69
|
-
"menu_type_id" => 1
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
"name" => Faker::Food.dish,
|
|
73
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
74
|
-
"menu_category_id" => 2,
|
|
75
|
-
"menu_type_id" => 1
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
"name" => Faker::Food.dish,
|
|
79
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
80
|
-
"menu_category_id" => 2,
|
|
81
|
-
"menu_type_id" => 2
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
"name" => Faker::Food.dish,
|
|
85
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
86
|
-
"menu_category_id" => 2,
|
|
87
|
-
"menu_type_id" => 2
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
"name" => Faker::Food.dish,
|
|
91
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
92
|
-
"menu_category_id" => 2,
|
|
93
|
-
"menu_type_id" => 2
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
"name" => Faker::Food.dish,
|
|
97
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
98
|
-
"menu_category_id" => 2,
|
|
99
|
-
"menu_type_id" => 3
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
"name" => Faker::Food.dish,
|
|
103
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
104
|
-
"menu_category_id" => 2,
|
|
105
|
-
"menu_type_id" => 3
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
"name" => Faker::Food.dish,
|
|
109
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
110
|
-
"menu_category_id" => 2,
|
|
111
|
-
"menu_type_id" => 3
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
"name" => Faker::Food.dish,
|
|
115
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
116
|
-
"menu_category_id" => 3,
|
|
117
|
-
"menu_type_id" => 1
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
"name" => Faker::Food.dish,
|
|
121
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
122
|
-
"menu_category_id" => 3,
|
|
123
|
-
"menu_type_id" => 1
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
"name" => Faker::Food.dish,
|
|
127
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
128
|
-
"menu_category_id" => 3,
|
|
129
|
-
"menu_type_id" => 1
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
"name" => Faker::Food.dish,
|
|
133
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
134
|
-
"menu_category_id" => 3,
|
|
135
|
-
"menu_type_id" => 2
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
"name" => Faker::Food.dish,
|
|
139
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
140
|
-
"menu_category_id" => 3,
|
|
141
|
-
"menu_type_id" => 2
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
"name" => Faker::Food.dish,
|
|
145
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
146
|
-
"menu_category_id" => 3,
|
|
147
|
-
"menu_type_id" => 2
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
"name" => Faker::Food.dish,
|
|
151
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
152
|
-
"menu_category_id" => 3,
|
|
153
|
-
"menu_type_id" => 3
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
"name" => Faker::Food.dish,
|
|
157
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
158
|
-
"menu_category_id" => 3,
|
|
159
|
-
"menu_type_id" => 3
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
"name" => Faker::Food.dish,
|
|
163
|
-
"price" => Faker::Number.between(from: 1, to: 9),
|
|
164
|
-
"menu_category_id" => 3,
|
|
165
|
-
"menu_type_id" => 3
|
|
166
|
-
},
|
|
167
|
-
]
|
|
168
|
-
end
|
|
1
|
+
require 'faker'
|
|
2
|
+
class Menu
|
|
3
|
+
def self.get_menu
|
|
4
|
+
return [
|
|
5
|
+
{
|
|
6
|
+
"name" => Faker::Food.dish,
|
|
7
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
8
|
+
"menu_category_id" => 1,
|
|
9
|
+
"menu_type_id" => 1
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name" => Faker::Food.dish,
|
|
13
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
14
|
+
"menu_category_id" => 1,
|
|
15
|
+
"menu_type_id" => 1
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"name" => Faker::Food.dish,
|
|
19
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
20
|
+
"menu_category_id" => 1,
|
|
21
|
+
"menu_type_id" => 1
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"name" => Faker::Food.dish,
|
|
25
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
26
|
+
"menu_category_id" => 1,
|
|
27
|
+
"menu_type_id" => 2
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"name" => Faker::Food.dish,
|
|
31
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
32
|
+
"menu_category_id" => 1,
|
|
33
|
+
"menu_type_id" => 2
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name" => Faker::Food.dish,
|
|
37
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
38
|
+
"menu_category_id" => 1,
|
|
39
|
+
"menu_type_id" => 2
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name" => Faker::Food.dish,
|
|
43
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
44
|
+
"menu_category_id" => 1,
|
|
45
|
+
"menu_type_id" => 3
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"name" => Faker::Food.dish,
|
|
49
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
50
|
+
"menu_category_id" => 1,
|
|
51
|
+
"menu_type_id" => 3
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"name" => Faker::Food.dish,
|
|
55
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
56
|
+
"menu_category_id" => 1,
|
|
57
|
+
"menu_type_id" => 3
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"name" => Faker::Food.dish,
|
|
61
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
62
|
+
"menu_category_id" => 2,
|
|
63
|
+
"menu_type_id" => 1
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"name" => Faker::Food.dish,
|
|
67
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
68
|
+
"menu_category_id" => 2,
|
|
69
|
+
"menu_type_id" => 1
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"name" => Faker::Food.dish,
|
|
73
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
74
|
+
"menu_category_id" => 2,
|
|
75
|
+
"menu_type_id" => 1
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"name" => Faker::Food.dish,
|
|
79
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
80
|
+
"menu_category_id" => 2,
|
|
81
|
+
"menu_type_id" => 2
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"name" => Faker::Food.dish,
|
|
85
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
86
|
+
"menu_category_id" => 2,
|
|
87
|
+
"menu_type_id" => 2
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"name" => Faker::Food.dish,
|
|
91
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
92
|
+
"menu_category_id" => 2,
|
|
93
|
+
"menu_type_id" => 2
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"name" => Faker::Food.dish,
|
|
97
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
98
|
+
"menu_category_id" => 2,
|
|
99
|
+
"menu_type_id" => 3
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"name" => Faker::Food.dish,
|
|
103
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
104
|
+
"menu_category_id" => 2,
|
|
105
|
+
"menu_type_id" => 3
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"name" => Faker::Food.dish,
|
|
109
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
110
|
+
"menu_category_id" => 2,
|
|
111
|
+
"menu_type_id" => 3
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"name" => Faker::Food.dish,
|
|
115
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
116
|
+
"menu_category_id" => 3,
|
|
117
|
+
"menu_type_id" => 1
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"name" => Faker::Food.dish,
|
|
121
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
122
|
+
"menu_category_id" => 3,
|
|
123
|
+
"menu_type_id" => 1
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"name" => Faker::Food.dish,
|
|
127
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
128
|
+
"menu_category_id" => 3,
|
|
129
|
+
"menu_type_id" => 1
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"name" => Faker::Food.dish,
|
|
133
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
134
|
+
"menu_category_id" => 3,
|
|
135
|
+
"menu_type_id" => 2
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"name" => Faker::Food.dish,
|
|
139
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
140
|
+
"menu_category_id" => 3,
|
|
141
|
+
"menu_type_id" => 2
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"name" => Faker::Food.dish,
|
|
145
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
146
|
+
"menu_category_id" => 3,
|
|
147
|
+
"menu_type_id" => 2
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"name" => Faker::Food.dish,
|
|
151
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
152
|
+
"menu_category_id" => 3,
|
|
153
|
+
"menu_type_id" => 3
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"name" => Faker::Food.dish,
|
|
157
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
158
|
+
"menu_category_id" => 3,
|
|
159
|
+
"menu_type_id" => 3
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"name" => Faker::Food.dish,
|
|
163
|
+
"price" => Faker::Number.between(from: 1, to: 9),
|
|
164
|
+
"menu_category_id" => 3,
|
|
165
|
+
"menu_type_id" => 3
|
|
166
|
+
},
|
|
167
|
+
]
|
|
168
|
+
end
|
|
169
169
|
end
|
data/lib/model/user.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
class User
|
|
2
|
-
def initialize(menu_type_id)
|
|
3
|
-
@menu_type_id = menu_type_id
|
|
4
|
-
end
|
|
5
|
-
|
|
6
|
-
def menu_type_id
|
|
7
|
-
@menu_type_id
|
|
8
|
-
end
|
|
1
|
+
class User
|
|
2
|
+
def initialize(menu_type_id)
|
|
3
|
+
@menu_type_id = menu_type_id
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def menu_type_id
|
|
7
|
+
@menu_type_id
|
|
8
|
+
end
|
|
9
9
|
end
|
data/lib/model/user_budget.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
class UserBudget
|
|
2
|
-
def initialize(budget_type, amount)
|
|
3
|
-
@budget_type = budget_type
|
|
4
|
-
@amount = amount
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def budget_type
|
|
8
|
-
@budget_type
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def amount
|
|
12
|
-
@amount
|
|
13
|
-
end
|
|
1
|
+
class UserBudget
|
|
2
|
+
def initialize(budget_type, amount)
|
|
3
|
+
@budget_type = budget_type
|
|
4
|
+
@amount = amount
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def budget_type
|
|
8
|
+
@budget_type
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def amount
|
|
12
|
+
@amount
|
|
13
|
+
end
|
|
14
14
|
end
|
data/lib/monthly_plan.rb
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
require '
|
|
2
|
-
|
|
3
|
-
class MonthlyPlan <
|
|
4
|
-
|
|
5
|
-
def
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
require 'daily_plan_decorator'
|
|
2
|
+
|
|
3
|
+
class MonthlyPlan < DailyPlanDecorator
|
|
4
|
+
|
|
5
|
+
def initialize(daily_plan)
|
|
6
|
+
super(daily_plan)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def budget
|
|
10
|
+
@daily_plan / 31
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def generate_meal_plan
|
|
14
|
+
meal_plan = Array.new
|
|
15
|
+
31.times do |n|
|
|
16
|
+
meal_plan.push(@daily_plan.generate_meal_plan)
|
|
17
|
+
end
|
|
18
|
+
return meal_plan
|
|
19
|
+
end
|
|
19
20
|
end
|
data/lib/weekly_plan.rb
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
require '
|
|
2
|
-
|
|
3
|
-
class WeeklyPlan <
|
|
4
|
-
|
|
5
|
-
def
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
require 'daily_plan_decorator'
|
|
2
|
+
|
|
3
|
+
class WeeklyPlan < DailyPlanDecorator
|
|
4
|
+
|
|
5
|
+
def initialize(daily_plan)
|
|
6
|
+
super(daily_plan)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def budget
|
|
10
|
+
@daily_plan / 7
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def generate_meal_plan
|
|
14
|
+
meal_plan = Array.new
|
|
15
|
+
7.times do |n|
|
|
16
|
+
meal_plan.push(@daily_plan.generate_meal_plan)
|
|
17
|
+
end
|
|
18
|
+
return meal_plan
|
|
19
|
+
end
|
|
19
20
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: meal_budget_planner
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Onyeka Onwochei
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-12-
|
|
11
|
+
date: 2019-12-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Meal Budgeting based on Meal Type (vegan, vegeterians and none) and Budget
|
|
14
14
|
plan(daily weekly or monthly)
|
|
@@ -18,12 +18,12 @@ extensions: []
|
|
|
18
18
|
extra_rdoc_files: []
|
|
19
19
|
files:
|
|
20
20
|
- lib/daily_plan.rb
|
|
21
|
-
- lib/
|
|
21
|
+
- lib/daily_plan_decorator.rb
|
|
22
|
+
- lib/meal_planner.rb
|
|
22
23
|
- lib/mock/menu.rb
|
|
23
24
|
- lib/model/user.rb
|
|
24
25
|
- lib/model/user_budget.rb
|
|
25
26
|
- lib/monthly_plan.rb
|
|
26
|
-
- lib/plan.rb
|
|
27
27
|
- lib/weekly_plan.rb
|
|
28
28
|
homepage: http://rubygems.org/gems/meal_budget_planner
|
|
29
29
|
licenses: []
|
data/lib/meal_plan.rb
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
require 'daily_plan'
|
|
2
|
-
require 'weekly_plan'
|
|
3
|
-
require 'monthly_plan'
|
|
4
|
-
|
|
5
|
-
class MealPlan
|
|
6
|
-
attr_reader :user, :menu, :budget, :BREAKFAST_PERCENT, :LUNCH_PERCENT, :DINNER_PERCENT, :BREAKFAST_IDENTIFIER, :LUNCH_IDENTIFIER, :DINNER_IDENTIFIER, :VEGAN, :VEGETERIAN, :NONVEGAN
|
|
7
|
-
attr_accessor :plan_type
|
|
8
|
-
|
|
9
|
-
def initialize(plan_type,user,menu,budget)
|
|
10
|
-
@plan_type = plan_type
|
|
11
|
-
@user = user
|
|
12
|
-
@menu = menu
|
|
13
|
-
@budget = budget.amount
|
|
14
|
-
@BREAKFAST_PERCENT = 25
|
|
15
|
-
@LUNCH_PERCENT = 40
|
|
16
|
-
@DINNER_PERCENT = 35
|
|
17
|
-
@BREAKFAST_IDENTIFIER = 1
|
|
18
|
-
@LUNCH_IDENTIFIER = 2
|
|
19
|
-
@DINNER_IDENTIFIER = 3
|
|
20
|
-
@VEGAN = 1
|
|
21
|
-
@VEGETERIAN = 2
|
|
22
|
-
@NONVEGAN = 3
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def generate
|
|
26
|
-
@plan_type.generate_meal_plan(self)
|
|
27
|
-
end
|
|
28
|
-
end
|
data/lib/plan.rb
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
class Plan
|
|
2
|
-
|
|
3
|
-
def generate_meal_plan
|
|
4
|
-
raise NotImplementedError, 'Cannot directly call abstract class'
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def budget
|
|
8
|
-
@budget
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def get_price(percent)
|
|
12
|
-
return (budget * percent) / 100
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def get_user_menu(price, menu_category_id)
|
|
16
|
-
return @menu.select {|menu| menu["price"] <= price && menu["menu_category_id"] == menu_category_id && menu["menu_type_id"] == @user.menu_type_id }
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
end
|