meal_budget_planner 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6c6604ce10bc7e33669607231e3c07226e8bd0cf4334e81f429183c7aa3d6f4e
4
+ data.tar.gz: d6ba4421adfbb8cbb8980fe920e5ed705b3e1ba780b219de1eea4170acfb7207
5
+ SHA512:
6
+ metadata.gz: 6cf64a4a57b1e02ed193ffa68c737d994ed13abe015d690d17d630dee12b8daa066c2dc79edc050e0bcbf794c6de48bd795766bc5d7916d6a49f31e479b28b4e
7
+ data.tar.gz: 270e3587cd01d305690a6e7c3977c6875137896374c6cde81f85922ef95bac1b912079431f520ca8aa11e5b021dd42a785a773349d6f9f813e1cbec3aa653877
@@ -0,0 +1,15 @@
1
+ require 'plan'
2
+
3
+ class DailyPlan < Plan
4
+
5
+ def generate_meal_plan(context)
6
+ @user = context.user
7
+ @menu = context.menu
8
+ @budget = context.budget
9
+ return {
10
+ :breakfast => get_user_menu(get_price(context.BREAKFAST_PERCENT), context.BREAKFAST_IDENTIFIER).sample,
11
+ :lunch => get_user_menu(get_price(context.LUNCH_PERCENT), context.LUNCH_IDENTIFIER).sample,
12
+ :dinner => get_user_menu(get_price(context.DINNER_PERCENT), context.DINNER_IDENTIFIER).sample
13
+ }
14
+ end
15
+ end
@@ -0,0 +1,28 @@
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
@@ -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
@@ -0,0 +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
9
+ end
@@ -0,0 +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
14
+ end
@@ -0,0 +1,19 @@
1
+ require 'plan'
2
+
3
+ class MonthlyPlan < Plan
4
+
5
+ def generate_meal_plan(context)
6
+ @user = context.user
7
+ @menu = context.menu
8
+ @budget = context.budget
9
+ meal_plan = Array.new
10
+ 31.times do |n|
11
+ meal_plan.push({
12
+ :breakfast => get_user_menu(get_price(context.BREAKFAST_PERCENT), context.BREAKFAST_IDENTIFIER).sample,
13
+ :lunch => get_user_menu(get_price(context.LUNCH_PERCENT), context.LUNCH_IDENTIFIER).sample,
14
+ :dinner => get_user_menu(get_price(context.DINNER_PERCENT), context.DINNER_IDENTIFIER).sample
15
+ })
16
+ end
17
+ return meal_plan
18
+ end
19
+ end
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,19 @@
1
+ require 'plan'
2
+
3
+ class WeeklyPlan < Plan
4
+
5
+ def generate_meal_plan(context)
6
+ @user = context.user
7
+ @menu = context.menu
8
+ @budget = context.budget
9
+ meal_plan = Array.new
10
+ 7.times do |n|
11
+ meal_plan.push({
12
+ :breakfast => get_user_menu(get_price(context.BREAKFAST_PERCENT), context.BREAKFAST_IDENTIFIER).sample,
13
+ :lunch => get_user_menu(get_price(context.LUNCH_PERCENT), context.LUNCH_IDENTIFIER).sample,
14
+ :dinner => get_user_menu(get_price(context.DINNER_PERCENT), context.DINNER_IDENTIFIER).sample
15
+ })
16
+ end
17
+ return meal_plan
18
+ end
19
+ 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.1
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Onyeka Onwochei
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-12-06 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/meal_plan.rb
22
+ - lib/mock/menu.rb
23
+ - lib/model/user.rb
24
+ - lib/model/user_budget.rb
25
+ - lib/monthly_plan.rb
26
+ - lib/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: []