class NutritionCalculator::DietPeriod

Constants

CALORIES_PER_KG

Attributes

calendar[RW]

Public Class Methods

new(length:, start_date:, resting_metabolic_rate:, weight_loss_goal_in_kg:, calendar: Date) click to toggle source
# File lib/nutrition_calculator/diet_period.rb, line 11
def initialize(length:, start_date:, resting_metabolic_rate:,
               weight_loss_goal_in_kg:, calendar: Date)
  self.length = length
  self.start_date = start_date
  self.resting_metabolic_rate = resting_metabolic_rate
  self.weight_loss_goal_in_kg = weight_loss_goal_in_kg
  self.calendar = calendar
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/nutrition_calculator/diet_period.rb, line 57
def <=>(other)
  start_date <=> other.to_date
end
succ() click to toggle source
# File lib/nutrition_calculator/diet_period.rb, line 51
def succ
  self.clone.tap do |period|
    period.start_date = start_date + length
  end
end

Private Instance Methods

current_cycle() click to toggle source
# File lib/nutrition_calculator/diet_period.rb, line 69
def current_cycle
  (self..calendar.today).to_a.last
end
current_cycle_start_date() click to toggle source
# File lib/nutrition_calculator/diet_period.rb, line 65
def current_cycle_start_date
  current_cycle.start_date
end
planned_calorie_deficit() click to toggle source
# File lib/nutrition_calculator/diet_period.rb, line 77
def planned_calorie_deficit
  (weight_loss_goal_in_kg * CALORIES_PER_KG).ceil
end
rmr_for_period() click to toggle source
# File lib/nutrition_calculator/diet_period.rb, line 73
def rmr_for_period
  resting_metabolic_rate * length
end