Skip to content

Instantly share code, notes, and snippets.

@quigebo
Created October 5, 2011 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quigebo/1265337 to your computer and use it in GitHub Desktop.
Save quigebo/1265337 to your computer and use it in GitHub Desktop.
module CalorieCalculator
def caloric_need
caloric_need_without_goal + calorie_need
end
private
# formula from http://www.bodybuilding.com/fun/issa64.htm
def caloric_need_without_goal
(weight * gender_multiplier * weight_multiplier * bodyfat_multiplier * activity_multiplier).round
end
def calorie_need
case goal
when -2 then -500
when -1 then -200
when 1 then 200
when 2 then 500
else
0
end
end
def gender_multiplier
male? ? 1.0 : 0.9
end
def weight_multiplier
24
end
def bodyfat_multiplier
case bodyfat
when very_low_bodyfat then 1.0
when low_bodyfat then 0.95
when high_bodyfat then 0.90
when very_high_bodyfat then 0.85
else 1
end
end
def activity_multiplier
case activity_level
when 'very_light' then 1.3
when 'light' then 1.55
when 'average' then 1.65
when 'fit' then 1.8
when 'athlete' then 2.0
else 1
end
end
def very_low_bodyfat
male? ? 0.0..0.14 : 0.14..0.18
end
def low_bodyfat
male? ? 0.14..0.20 : 0.18..0.28
end
def high_bodyfat
male? ? 0.20..0.28 : 0.28..0.38
end
def very_high_bodyfat
male? ? 0.28..1 : 0.38..1
end
def male?; gender == 'm'; end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment