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.
-
#num_days_to_budget ⇒ Integer
The number of days across which to budget the remaining net calorie goal for 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_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.
Instance Method Summary collapse
- #diet_period=(diet_period) ⇒ Object
-
#initialize(diet_period: nil, source_data: nil) ⇒ CalorieBudgeter
constructor
A new instance of CalorieBudgeter.
- #source_data=(source_data) ⇒ Object
Methods included from CachedOutputsWithRecalculation
def_input, def_output, extended
Constructor Details
#initialize(diet_period: nil, source_data: nil) ⇒ CalorieBudgeter
Returns a new instance of CalorieBudgeter.
48 49 50 51 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 48 def initialize(diet_period: nil, source_data: nil) self.diet_period = diet_period if diet_period self.source_data = source_data if source_data end |
Instance Attribute Details
#calories_burned ⇒ Integer
Returns The total number of calories burned via exercise today.
111 112 113 114 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 111 def_input :calories_burned, validate_with: ->(value) { value.kind_of?(Integer) \ && value >= 0 } |
#calories_consumed ⇒ Integer
Returns The total number of calories consumed today.
104 105 106 107 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 104 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.
127 128 129 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 127 def_output :calories_remaining do [0, remaining_to_target].max end |
#daily_calorie_goal ⇒ Integer (readonly)
Returns The number of net calories that should be consumed today to meet the weekly calorie goal.
170 171 172 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 170 def_output :daily_calorie_goal do (remaining_calories_this_week.to_f / num_days_to_budget).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.
134 135 136 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 134 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).
121 122 123 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 121 def_output :net_calorie_consumption do calories_consumed - calories_burned end |
#num_days_to_budget ⇒ Integer
Returns The number of days across which to budget the remaining net calorie goal for the week. This includes the current day.
98 99 100 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 98 def_input :num_days_to_budget, validate_with: ->(value) { (1..7).include?(value) } |
#predicted_calorie_consumption ⇒ Integer (readonly)
Returns The number of calories that will likely be consumed today (the greater of actual consumption or target consumption).
142 143 144 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 142 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.
150 151 152 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 150 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.
90 91 92 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 90 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).
178 179 180 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 178 def_output :remaining_calories_this_week do weekly_calorie_goal - prior_days_calories end |
#remaining_to_target ⇒ Integer (readonly)
Returns The number of calories that must still be consumed to hit the day’s target.
157 158 159 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 157 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.
69 70 71 72 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 69 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.
163 164 165 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 163 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.
77 78 79 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 77 def_input :weekly_calorie_goal, validate_with: ->(value) { value.kind_of?(Integer) } |
Instance Method Details
#diet_period=(diet_period) ⇒ Object
53 54 55 56 57 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 53 def diet_period=(diet_period) self. = diet_period. self.weekly_calorie_goal = diet_period.net_calorie_goal self.num_days_to_budget = diet_period.days_remaining end |
#source_data=(source_data) ⇒ Object
59 60 61 62 63 |
# File 'lib/nutrition_calculator/calorie_budgeter.rb', line 59 def source_data=(source_data) self.prior_days_calories = source_data.prior_days_net_calories self.calories_consumed = source_data.calories_consumed_today self.calories_burned = source_data.calories_burned_today end |