meal_budget_planner 1.0.0 → 1.0.1
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 +9 -33
- data/lib/meal_plan.rb +28 -0
- data/lib/monthly_plan.rb +11 -12
- data/lib/plan.rb +19 -0
- data/lib/weekly_plan.rb +11 -12
- metadata +4 -4
- data/lib/daily_plan_decorator.rb +0 -11
- data/lib/meal_planner.rb +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c6604ce10bc7e33669607231e3c07226e8bd0cf4334e81f429183c7aa3d6f4e
|
4
|
+
data.tar.gz: d6ba4421adfbb8cbb8980fe920e5ed705b3e1ba780b219de1eea4170acfb7207
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cf64a4a57b1e02ed193ffa68c737d994ed13abe015d690d17d630dee12b8daa066c2dc79edc050e0bcbf794c6de48bd795766bc5d7916d6a49f31e479b28b4e
|
7
|
+
data.tar.gz: 270e3587cd01d305690a6e7c3977c6875137896374c6cde81f85922ef95bac1b912079431f520ca8aa11e5b021dd42a785a773349d6f9f813e1cbec3aa653877
|
data/lib/daily_plan.rb
CHANGED
@@ -1,39 +1,15 @@
|
|
1
|
-
|
1
|
+
require 'plan'
|
2
2
|
|
3
|
-
|
3
|
+
class DailyPlan < Plan
|
4
4
|
|
5
|
-
def
|
6
|
-
@user = user
|
7
|
-
@menu = menu
|
8
|
-
@budget = budget
|
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
|
5
|
+
def generate_meal_plan(context)
|
6
|
+
@user = context.user
|
7
|
+
@menu = context.menu
|
8
|
+
@budget = context.budget
|
33
9
|
return {
|
34
|
-
:breakfast => get_user_menu(get_price(
|
35
|
-
:lunch => get_user_menu(get_price(
|
36
|
-
:dinner => get_user_menu(get_price(
|
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
|
37
13
|
}
|
38
14
|
end
|
39
15
|
end
|
data/lib/meal_plan.rb
ADDED
@@ -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
|
data/lib/monthly_plan.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
|
-
require '
|
1
|
+
require 'plan'
|
2
2
|
|
3
|
-
class MonthlyPlan <
|
3
|
+
class MonthlyPlan < Plan
|
4
4
|
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def budget
|
10
|
-
@daily_plan / 31
|
11
|
-
end
|
12
|
-
|
13
|
-
def generate_meal_plan
|
5
|
+
def generate_meal_plan(context)
|
6
|
+
@user = context.user
|
7
|
+
@menu = context.menu
|
8
|
+
@budget = context.budget
|
14
9
|
meal_plan = Array.new
|
15
10
|
31.times do |n|
|
16
|
-
meal_plan.push(
|
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
|
+
})
|
17
16
|
end
|
18
17
|
return meal_plan
|
19
18
|
end
|
data/lib/plan.rb
ADDED
@@ -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
|
data/lib/weekly_plan.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
|
-
require '
|
1
|
+
require 'plan'
|
2
2
|
|
3
|
-
class WeeklyPlan <
|
3
|
+
class WeeklyPlan < Plan
|
4
4
|
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def budget
|
10
|
-
@daily_plan / 7
|
11
|
-
end
|
12
|
-
|
13
|
-
def generate_meal_plan
|
5
|
+
def generate_meal_plan(context)
|
6
|
+
@user = context.user
|
7
|
+
@menu = context.menu
|
8
|
+
@budget = context.budget
|
14
9
|
meal_plan = Array.new
|
15
10
|
7.times do |n|
|
16
|
-
meal_plan.push(
|
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
|
+
})
|
17
16
|
end
|
18
17
|
return meal_plan
|
19
18
|
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.1
|
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-06 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/
|
22
|
-
- lib/meal_planner.rb
|
21
|
+
- lib/meal_plan.rb
|
23
22
|
- lib/mock/menu.rb
|
24
23
|
- lib/model/user.rb
|
25
24
|
- lib/model/user_budget.rb
|
26
25
|
- 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/daily_plan_decorator.rb
DELETED
data/lib/meal_planner.rb
DELETED
@@ -1,66 +0,0 @@
|
|
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
|