Class: Beerxml::Recipe

Inherits:
Model
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/beerxml/recipe.rb

Instance Method Summary collapse

Methods inherited from Model

beerxml_name, beerxml_plural_name, collection_from_xml, #each_beerxml_relationship, from_xml, #from_xml, inherited, #read_xml_field, #to_beerxml, #to_xml, xml_attr_name

Instance Method Details

#beerxml_relationshipsObject

has n, :waters



20
21
22
# File 'lib/beerxml/recipe.rb', line 20

def beerxml_relationships
  [:hops, :fermentables, :miscs, :yeasts, :waters]
end

#calculate_fgObject



64
65
66
67
# File 'lib/beerxml/recipe.rb', line 64

def calculate_fg
  og = calculate_og
  Beerxml.round(og - ((og - 1) * yeasts.first.attenuation * 0.01), 3)
end

#calculate_ogObject



58
59
60
61
62
# File 'lib/beerxml/recipe.rb', line 58

def calculate_og
  total_ppg = fermentables.inject(0) { |v, f| v + f.total_ppg(efficiency) }
  og = 1 + ((total_ppg / batch_size.in_gallons.to_f) * 0.001)
  Beerxml.round(og, 3)
end

#colorObject



69
70
71
72
# File 'lib/beerxml/recipe.rb', line 69

def color
  color = fermentables.inject(0) { |v, f| v + f.total_color }
  Beerxml.round(1.4922 * ((color / batch_size.in_gallons.to_f) ** 0.6859), 1)
end

#tinsethObject Also known as: ibus



53
54
55
# File 'lib/beerxml/recipe.rb', line 53

def tinseth
  Beerxml.round(hops.select { |h| h.use == 'Boil' }.inject(0) { |v, h| v + h.tinseth(calculate_og, batch_size) }, 1)
end