nutrition_calculator 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/bin/run_calorie_budgeter +107 -0
- data/lib/nutrition_calculator/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd32e4e0cc71be61a0717bb8e04de917ed5743dc
|
4
|
+
data.tar.gz: 73c3d155d32120421554e8b4b3bd3442d05efe66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ae10f6a15caad532f47181d591171db462d881386f7e4ef96f7c1595144ed03a494ed7ca29d2412576031623bd5a8fd5dbb186582fc297a8ef02767b9abe393
|
7
|
+
data.tar.gz: 04e310f5b78a9eb8e96e9cc63eef0402870f48046297fb2b7f4ff4aff812621e4b4d58f863a79c402a5c9996b231bde7d922b9a3219b2d38b9a60748e3c29b37
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
case ARGV[0]
|
4
|
+
when nil, '-h', '--help'
|
5
|
+
puts <<-EOF
|
6
|
+
USAGE: run_calorie_budgeter {DATA_FILE}
|
7
|
+
|
8
|
+
DATA_FILE should be a YAML file with the following format:
|
9
|
+
|
10
|
+
----
|
11
|
+
resting_metabolic_rate: 1950
|
12
|
+
weekly_calorie_goal: 10_150
|
13
|
+
|
14
|
+
1:
|
15
|
+
calories_consumed: 1_998
|
16
|
+
calories_burned: 182
|
17
|
+
2:
|
18
|
+
calories_consumed: 1_998
|
19
|
+
calories_burned: 182
|
20
|
+
3:
|
21
|
+
calories_consumed: 1_998
|
22
|
+
calories_burned: 182
|
23
|
+
4:
|
24
|
+
calories_consumed: 1_998
|
25
|
+
calories_burned: 182
|
26
|
+
5:
|
27
|
+
calories_consumed: 1_998
|
28
|
+
calories_burned: 182
|
29
|
+
6:
|
30
|
+
calories_consumed: 1_998
|
31
|
+
calories_burned: 182
|
32
|
+
7:
|
33
|
+
calories_consumed: 1_998
|
34
|
+
calories_burned: 182
|
35
|
+
----
|
36
|
+
|
37
|
+
Each numbered section in the file corresponds to a day of the week, where:
|
38
|
+
|
39
|
+
1: Monday
|
40
|
+
2: Tuesday
|
41
|
+
3: Wednesday
|
42
|
+
4: Thursday
|
43
|
+
5: Friday
|
44
|
+
6: Saturday
|
45
|
+
7: Sunday
|
46
|
+
|
47
|
+
This program considers Monday to be the start of the dieting week (i.e. that
|
48
|
+
is when the weekly calorie budget starts over).
|
49
|
+
|
50
|
+
EOF
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
|
54
|
+
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
|
55
|
+
|
56
|
+
require 'nutrition_calculator/calorie_budgeter'
|
57
|
+
require 'yaml'
|
58
|
+
require 'date'
|
59
|
+
|
60
|
+
|
61
|
+
def data
|
62
|
+
@data ||= YAML.load_file(ARGV.first)
|
63
|
+
end
|
64
|
+
|
65
|
+
def current_day_num
|
66
|
+
day = Date.new.wday
|
67
|
+
day = 7 if day == 0 # Sunday is the 7th day of the diet week
|
68
|
+
day
|
69
|
+
end
|
70
|
+
|
71
|
+
def data_for_day(day_num)
|
72
|
+
data.fetch(day_num) do
|
73
|
+
{ 'calories_burned' => 0, 'calories_consumed' => 0 }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def prior_days_net_calories
|
78
|
+
(1..current_day_num).reduce { |sum, day_num|
|
79
|
+
day_data = data_for_day(day_num)
|
80
|
+
sum + (day_data['calories_consumed'] - day_data['calories_burned'])
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
def today
|
85
|
+
data_for_day(current_day_num)
|
86
|
+
end
|
87
|
+
|
88
|
+
def calories_burned_today
|
89
|
+
today['calories_burned']
|
90
|
+
end
|
91
|
+
|
92
|
+
def calories_consumed_today
|
93
|
+
today['calories_consumed']
|
94
|
+
end
|
95
|
+
|
96
|
+
cb = NutritionCalculator::CalorieBudgeter.new
|
97
|
+
cb.resting_metabolic_rate = data['resting_metabolic_rate']
|
98
|
+
cb.weekly_calorie_goal = data['weekly_calorie_goal']
|
99
|
+
cb.current_day_of_week = current_day_num
|
100
|
+
cb.prior_days_calories = prior_days_net_calories
|
101
|
+
cb.calories_burned = calories_burned_today
|
102
|
+
cb.calories_consumed = calories_consumed_today
|
103
|
+
|
104
|
+
puts "You have consumed #{cb.calories_consumed} calories today."
|
105
|
+
puts "You have burned #{cb.calories_burned} calories today."
|
106
|
+
puts "You need to consume #{cb.calories_remaining} more calories today to hit your target of #{cb.target_daily_calorie_consumption}."
|
107
|
+
puts "You need to exercise to burn off #{cb.exercise_calories_remaining} more calories today to hit your net calorie goal of #{cb.daily_calorie_goal}."
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nutrition_calculator
|
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
|
- John Wilger
|
@@ -99,7 +99,8 @@ description: "\n NutritionCalculator provides a set of core libraries to help
|
|
99
99
|
and monitoring the nutritional balance of a diet.\n "
|
100
100
|
email:
|
101
101
|
- johnwilger@gmail.com
|
102
|
-
executables:
|
102
|
+
executables:
|
103
|
+
- run_calorie_budgeter
|
103
104
|
extensions: []
|
104
105
|
extra_rdoc_files: []
|
105
106
|
files:
|
@@ -111,6 +112,7 @@ files:
|
|
111
112
|
- LICENSE.txt
|
112
113
|
- README.md
|
113
114
|
- Rakefile
|
115
|
+
- bin/run_calorie_budgeter
|
114
116
|
- features/calorie_budgeter.feature
|
115
117
|
- features/step_definitions/.keep
|
116
118
|
- features/step_definitions/calorie_budgeter_steps.rb
|