meal_budget_planner 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/daily_plan.rb +39 -0
- data/lib/daily_plan_decorator.rb +11 -0
- data/lib/meal_planner.rb +66 -0
- data/lib/mock/menu.rb +169 -0
- data/lib/model/user.rb +9 -0
- data/lib/model/user_budget.rb +14 -0
- data/lib/monthly_plan.rb +20 -0
- data/lib/weekly_plan.rb +20 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3ee203ce6266945af356a5dff933ae74f926f578d34dd48152571429641cc071
|
4
|
+
data.tar.gz: 9d8155d21e80d1c9f2ee6bd7915e3f816dba0b706b1eefae9ec6cbf220667d81
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a97972d6787c153650d037282e3fbbaa10b8bd6a001da3d704819b49e824b22092af1e4cf4cb2933a8b3e7819df473bfa0541126bc6f0a7428b136e4cbe8affa
|
7
|
+
data.tar.gz: 3c68dcad30597af69c4f974e9243d6e9ad46f99ce10ce3f0a107a148ced750c3200fe7fa64e797810756213c1500590cab29e5b2fd3a27b547592c38107218e2
|
data/lib/daily_plan.rb
ADDED
@@ -0,0 +1,39 @@
|
|
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
|
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
ADDED
@@ -0,0 +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
|
169
|
+
end
|
data/lib/model/user.rb
ADDED
data/lib/monthly_plan.rb
ADDED
@@ -0,0 +1,20 @@
|
|
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
|
20
|
+
end
|
data/lib/weekly_plan.rb
ADDED
@@ -0,0 +1,20 @@
|
|
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
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: meal_budget_planner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Onyeka Onwochei
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Meal Budgeting based on Meal Type (vegan, vegeterians and none) and Budget
|
14
|
+
plan(daily weekly or monthly)
|
15
|
+
email: Donyeka32@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/daily_plan.rb
|
21
|
+
- lib/daily_plan_decorator.rb
|
22
|
+
- lib/meal_planner.rb
|
23
|
+
- lib/mock/menu.rb
|
24
|
+
- lib/model/user.rb
|
25
|
+
- lib/model/user_budget.rb
|
26
|
+
- lib/monthly_plan.rb
|
27
|
+
- lib/weekly_plan.rb
|
28
|
+
homepage: http://rubygems.org/gems/meal_budget_planner
|
29
|
+
licenses: []
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubygems_version: 3.0.3
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: Meal Budgeting
|
50
|
+
test_files: []
|