2016-01-12 18:43:00 -06:00
|
|
|
module RecipesHelper
|
2016-01-18 15:10:25 -06:00
|
|
|
def recipe_time(recipe)
|
|
|
|
output = ''.html_safe
|
|
|
|
|
|
|
|
if recipe.total_time.present?
|
|
|
|
output << "#{humanize_seconds(recipe.total_time.to_i.minutes)}"
|
|
|
|
if recipe.active_time.present?
|
|
|
|
output << " (#{humanize_seconds(recipe.active_time.to_i.minutes)} active)"
|
|
|
|
end
|
|
|
|
elsif recipe.active_time.present?
|
|
|
|
output << humanize_seconds(recipe.active_time.to_i.minutes)
|
|
|
|
end
|
|
|
|
|
|
|
|
output
|
|
|
|
end
|
|
|
|
|
|
|
|
def humanize_seconds(secs)
|
|
|
|
[[60, :s], [60, :m], [24, :h], [1000, :d]].map{ |count, name|
|
|
|
|
if secs > 0
|
|
|
|
secs, n = secs.divmod(count)
|
|
|
|
n == 0 ? nil : "#{n.to_i} #{name}"
|
|
|
|
end
|
|
|
|
}.compact.reverse.join(' ')
|
|
|
|
end
|
2016-06-22 13:49:03 -05:00
|
|
|
|
|
|
|
def nutrient_row(recipe, nutrients, heading, nutrient_name)
|
|
|
|
content_tag('tr') do
|
|
|
|
[
|
|
|
|
content_tag('td', heading),
|
|
|
|
recipe.parsed_yield ? content_tag('td', nutrients.send("#{nutrient_name}_per".to_sym, recipe.parsed_yield.number)) : nil,
|
|
|
|
content_tag('td', nutrients.send("#{nutrient_name}".to_sym))
|
|
|
|
].compact.join("\n".html_safe).html_safe
|
|
|
|
end
|
|
|
|
end
|
2016-01-12 18:43:00 -06:00
|
|
|
end
|