class BeerRecipe::RecipeWrapper
Constants
- SETS
Public Class Methods
new(record, actual_values: false)
click to toggle source
Calls superclass method
BeerRecipe::Wrapper::new
# File lib/beer_recipe/recipe_wrapper.rb, line 4 def initialize(record, actual_values: false) super(record) @actual_values = actual_values @sets = {} end
Public Instance Methods
abv()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 96 def abv @abv ||= @actual_values && actual_abv > 0 ? actual_abv : estimated_abv || calculated_abv end
actual_abv()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 84 def actual_abv strip_unit(recipe.abv) end
actual_color()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 142 def actual_color color_ebc end
actual_fg()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 72 def actual_fg recipe.fg end
actual_og()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 68 def actual_og recipe.og end
batch_size()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 52 def batch_size recipe.batch_size || 0 end
bitter_extracts()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 130 def bitter_extracts fermentables.select { |f| f.bitter_extract? } end
boil_time()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 199 def boil_time recipe.boil_time || 0 end
boil_time_period()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 211 def boil_time_period "PT#{'%0.f' % boil_time}M" end
calculated_abv()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 92 def calculated_abv BeerRecipe::Formula.new.sg_to_abv(og, fg) end
calculated_calories()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 228 def calculated_calories if has_final_values? BeerRecipe::Formula.new.calories(serving_size, abv, og, fg) else 0 end end
calculated_ibu()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 113 def calculated_ibu @calculated_ibu ||= begin ibu = 0 hops.each do |hop| ibu += hop.ibu end bitter_extracts.each do |f| ibu += f.ibu end ibu end end
calories()
click to toggle source
Returns calories per liter
# File lib/beer_recipe/recipe_wrapper.rb, line 220 def calories @calories ||= @actual_values && calculated_calories > 0 ? calculated_calories : estimated_calories end
color()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 138 def color @actual_values ? actual_color : estimated_color end
color_class()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 162 def color_class c = color_srm.to_i if c > 40 'srm-max' elsif c < 1 'srm-min' else "srm#{c}" end end
color_ebc()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 158 def color_ebc @color_ebc ||= BeerRecipe::Formula.new.srm_to_ebc(color_srm) end
color_hex()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 173 def color_hex "#%02x%02x%02x" % BeerRecipe::Formula.new.srm_to_rgb(color_srm) end
color_mcu()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 146 def color_mcu mcu = 0 fermentables.each do |f| mcu += f.mcu end mcu end
color_srm()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 154 def color_srm @color_srm ||= BeerRecipe::Formula.new.mcu_to_srm(color_mcu) end
date()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 14 def date recipe.date || nil end
estimated_abv()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 88 def estimated_abv strip_unit(recipe.est_abv) end
estimated_calories()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 224 def estimated_calories strip_unit(recipe.calories) end
estimated_color()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 134 def estimated_color strip_unit(recipe.est_color) end
estimated_fg()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 64 def estimated_fg strip_unit(recipe.est_fg) end
estimated_ibu()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 109 def estimated_ibu strip_unit(recipe.ibu) end
estimated_og()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 60 def estimated_og strip_unit(recipe.est_og) end
fg()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 80 def fg @fg ||= @actual_values && actual_fg > 0 ? actual_fg : estimated_fg || actual_fg || 0 end
file_name()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 38 def file_name I18n.transliterate(name.downcase.gsub(/\s+/, '_')).gsub(/[^a-z0-9_]/, '') end
formatted_color()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 177 def formatted_color "#{'%.0f' % color} EBC" end
gallons()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 56 def gallons batch_size * 0.264172 end
get_binding()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 18 def get_binding binding end
grains()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 126 def grains fermentables.select { |f| f.type == 'Grain' } end
has_final_values?()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 42 def has_final_values? og > 0 && fg > 0 && abv > 0 end
ibu()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 100 def ibu @ibu ||= @actual_values && calculated_ibu > 0 ? calculated_ibu : estimated_ibu || calculated_ibu end
mash()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 34 def mash @mash ||= BeerRecipe::MashWrapper.new(recipe.mash, self) unless recipe.mash.nil? end
method_missing(method, *args, &block)
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 22 def method_missing(method, *args, &block) if SETS.include?(method) @sets[method] ||= BeerRecipe::Wrapper.set(self, recipe.send(method)) else recipe.send(method, *args, &block) end end
og()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 76 def og @og ||= @actual_values && actual_og > 0 ? actual_og : estimated_og || actual_og || 0 end
real_extract()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 236 def real_extract @real_extract ||= if has_final_values? BeerRecipe::Formula.new.real_extract(og, fg) else 0 end end
recipe()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 10 def recipe @record end
respond_to_missing?(name, flag = true)
click to toggle source
Calls superclass method
BeerRecipe::Wrapper#respond_to_missing?
# File lib/beer_recipe/recipe_wrapper.rb, line 30 def respond_to_missing?(name, flag = true) SETS.include?(method) || recipe.respond_to?(name) || super end
serving_size()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 215 def serving_size 1000 end
strip_unit(value)
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 104 def strip_unit(value) return value if value.nil? || !value.kind_of?(String) value.gsub(/ \w+\Z/, '').to_f end
style_code()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 46 def style_code return "" if recipe.style.nil? || !recipe.style.respond_to?(:category_number) || !recipe.style.respond_to?(:style_letter) "#{recipe.style.category_number} #{recipe.style.style_letter}" end
total_grains()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 181 def total_grains return @total_grains if @total_grains @total_grains = 0 fermentables.each do |f| @total_grains += f.amount end @total_grains end
total_hops()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 190 def total_hops return @hop_weight if @hop_weight @hop_weight = 0 hops.each do |hop| @hop_weight += hop.amount end @hop_weight end
total_time()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 203 def total_time boil_time + mash.total_mash_time end
total_time_period()
click to toggle source
# File lib/beer_recipe/recipe_wrapper.rb, line 207 def total_time_period "PT#{'%0.f' % total_time}M" end