Class: NutritionCalculator::CalorieBudgeter
- Inherits:
-
Object
- Object
- NutritionCalculator::CalorieBudgeter
- Extended by:
- CachedOutputsWithRecalculation
- Defined in:
- lib/nutrition_calculator/calorie_budgeter.rb
Overview
Calculates Calorie Budget Per Day in Weekly Context
The ‘NutritionCalculator::CalorieBudgeter` is used to determine how many calories you need to consume and how many calories you need to burn via exercise for a given day in order to stay on target with your diet. In particular, it ensures that you consume at least enough to satisfy your resting metabolic rate each day, even if that means you need to burn off calories via exercise to keep on track. It operates on a weekly basis, so if you are over-/under-budget on a given day, the goals for the remainder of the week will be adjusted accordingly.
Inputs collapse
-
#calories_burned ⇒ Integer
The total number of calories burned via exercise today.
-
#calories_consumed ⇒ Integer
The total number of calories consumed today.
-
#current_day_of_week ⇒ Integer
The number of the day of the week.
-
#prior_days_calories ⇒ Integer
The total net calories from all days this week prior to the current day.
-
#resting_metabolic_rate ⇒ Integer
The daily resting metabolic rate in calories.
-
#weekly_calorie_goal ⇒ Integer
The total net calories (consumed - burned) planned for the week.
Outputs collapse
-
#calories_remaining ⇒ Integer
readonly
The number of calories remaining to consume today.
-
#daily_calorie_goal ⇒ Integer
readonly
The number of net calories that should be consumed today to meet the weekly calorie goal.
-
#exercise_calories_remaining ⇒ Integer
readonly
The number of calories that must still be burned today in order to meet the daily calorie goal.
-
#net_calorie_consumption ⇒ Integer
readonly
The net calories for the day (consumed - burned via exercise).
-
#predicted_calorie_consumption ⇒ Integer
readonly
The number of calories that will likely be consumed today (the greater of actual consumption or target consumption).
-
#predicted_overage ⇒ Integer
readonly
The number of calories consumed (or predicted to be consumed) that is greater than the daily calorie goal and not yet burned off via exercise.
-
#remaining_calories_this_week ⇒ Integer
readonly
The number of calories left in the calorie budget for the current week (does not include calories consumed today).
-
#remaining_days_of_week ⇒ Integer
readonly
The number of days remaining in the week, including the current day.
-
#remaining_to_target ⇒ Integer
readonly
The number of calories that must still be consumed to hit the day’s target.
-
#target_daily_calorie_consumption ⇒ Integer
readonly
The number of calories that should be consumed today.
Method Summary
Methods included from CachedOutputsWithRecalculation
def_input, def_output, extended
Instance Attribute Details
#calories_burned ⇒ Integer
Returns The total number of calories burned via exercise today.
95 96 97 98 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 95 def_input :calories_burned, validate_with: ->(value) { value.kind_of?(Integer) \ && value >= 0 } |
#calories_consumed ⇒ Integer
Returns The total number of calories consumed today.
88 89 90 91 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 88 def_input :calories_consumed, validate_with: ->(value) { value.kind_of?(Integer) \ && value >= 0 } |
#calories_remaining ⇒ Integer (readonly)
Returns The number of calories remaining to consume today.
111 112 113 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 111 def_output :calories_remaining do [0, remaining_to_target].max end |
#current_day_of_week ⇒ Integer
Returns The number of the day of the week.
82 83 84 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 82 def_input :current_day_of_week, validate_with: ->(value) { (1..7).include?(value) } |
#daily_calorie_goal ⇒ Integer (readonly)
Returns The number of net calories that should be consumed today to meet the weekly calorie goal.
154 155 156 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 154 def_output :daily_calorie_goal do (remaining_calories_this_week.to_f / remaining_days_of_week).round end |
#exercise_calories_remaining ⇒ Integer (readonly)
Returns The number of calories that must still be burned today in order to meet the daily calorie goal.
118 119 120 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 118 def_output :exercise_calories_remaining do [0, predicted_overage].max end |
#net_calorie_consumption ⇒ Integer (readonly)
Returns The net calories for the day (consumed - burned via exercise).
105 106 107 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 105 def_output :net_calorie_consumption do calories_consumed - calories_burned end |
#predicted_calorie_consumption ⇒ Integer (readonly)
Returns The number of calories that will likely be consumed today (the greater of actual consumption or target consumption).
126 127 128 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 126 def_output :predicted_calorie_consumption do [target_daily_calorie_consumption, calories_consumed].max end |
#predicted_overage ⇒ Integer (readonly)
Returns The number of calories consumed (or predicted to be consumed) that is greater than the daily calorie goal and not yet burned off via exercise.
134 135 136 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 134 def_output :predicted_overage do predicted_calorie_consumption - daily_calorie_goal - calories_burned end |
#prior_days_calories ⇒ Integer
Returns The total net calories from all days this week prior to the current day.
68 69 70 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 68 def_input :prior_days_calories, validate_with: ->(value) { value.kind_of?(Integer) } |
#remaining_calories_this_week ⇒ Integer (readonly)
Returns The number of calories left in the calorie budget for the current week (does not include calories consumed today).
162 163 164 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 162 def_output :remaining_calories_this_week do weekly_calorie_goal - prior_days_calories end |
#remaining_days_of_week ⇒ Integer (readonly)
Returns The number of days remaining in the week, including the current day.
169 170 171 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 169 def_output :remaining_days_of_week do 8 - current_day_of_week end |
#remaining_to_target ⇒ Integer (readonly)
Returns The number of calories that must still be consumed to hit the day’s target.
141 142 143 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 141 def_output :remaining_to_target do target_daily_calorie_consumption - calories_consumed end |
#resting_metabolic_rate ⇒ Integer
Returns The daily resting metabolic rate in calories.
47 48 49 50 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 47 def_input :resting_metabolic_rate, validate_with: ->(value) { value.kind_of?(Integer) \ && value > 0 } |
#target_daily_calorie_consumption ⇒ Integer (readonly)
Returns The number of calories that should be consumed today.
147 148 149 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 147 def_output :target_daily_calorie_consumption do [(daily_calorie_goal + calories_burned), ].max end |
#weekly_calorie_goal ⇒ Integer
Returns The total net calories (consumed - burned) planned for the week.
55 56 57 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 55 def_input :weekly_calorie_goal, validate_with: ->(value) { value.kind_of?(Integer) } |