Skip to content
This repository has been archived by the owner on Mar 4, 2022. It is now read-only.

Commit

Permalink
yeast model and fg calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
codekitchen committed Mar 8, 2011
1 parent cb7ba32 commit c785dde
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/beerxml/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,5 @@ def self.xml_attr_name(name)
end
end

%w(hop recipe fermentable).
%w(hop recipe fermentable yeast).
each { |f| require "beerxml/#{f}" }
7 changes: 6 additions & 1 deletion lib/beerxml/recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Beerxml::Recipe < Beerxml::Model
has n, :hops
has n, :fermentables
# has n, :miscs
# has n, :yeasts
has n, :yeasts
# has n, :waters

property :asst_brewer, String
Expand Down Expand Up @@ -56,4 +56,9 @@ def calculate_og
og = 1 + ((total_ppg / batch_size.in_gallons.to_f) * 0.001)
Beerxml.round(og, 3)
end

def calculate_fg
og = calculate_og
Beerxml.round(og - ((og - 1) * yeasts.first.attenuation * 0.01), 3)
end
end
26 changes: 26 additions & 0 deletions lib/beerxml/yeast.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Beerxml::Yeast < Beerxml::Model
include DataMapper::Resource

property :name, String, :required => true
property :type, Enum['Ale', 'Lager', 'Wheat', 'Wine', 'Champagne'], :required => true
property :form, Enum['Liquid', 'Dry', 'Slant', 'Culture'], :required => true
# TODO: sheesh... this can be a Weight instead, if amount_is_weight
property :amount, Volume, :required => true

property :amount_is_weight, Boolean
property :laboratory, String
property :product_id, String
property :min_temperature, Temperature
property :max_temperature, Temperature
property :flocculation, Enum[nil, 'Low', 'Medium', 'High', 'Very High']
property :attenuation, Float
property :notes, String, :length => 65535
property :best_for, String
property :times_cultured, Integer
property :max_reuse, Integer
property :add_to_secondary, Boolean

# these are not used in the xml
property :id, Serial
belongs_to :recipe, :required => false
end
20 changes: 20 additions & 0 deletions spec/parsing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ def check_parse(klass, file, node, attrs)
:hsi => 35.0,
})
end
it "should parse yeasts" do
check_parse(Beerxml::Yeast, "yeast", 3, {
:name => 'European Ale',
:type => 'Ale',
:form => 'Liquid',
:amount => 0.035,
:amount_is_weight => false,
:laboratory => 'White Labs',
:product_id => 'WLP011',
:min_temperature => 18.3,
:max_temperature => 21.1,
:flocculation => 'Medium',
:attenuation => 67.5,
:notes => "Malty, Northern European ale yeast. Low ester production, low sulfer, gives a clean profile. Low attenuation contributes to malty taste.",
:best_for => "Alt, Kolsch, malty English Ales, Fruit beers",
:max_reuse => 5,
:times_cultured => 0,
:add_to_secondary => false,
})
end
it "should parse recipes" do
recipe = check_parse(Beerxml::Recipe, "recipes", 3, {
:name => 'Dry Stout',
Expand Down
6 changes: 6 additions & 0 deletions spec/recipes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@
recipe.should be_valid
recipe.calculate_og.should == 1.056
end

it "should calculate the FG for an all grain batch" do
recipe = Beerxml::Recipe.new.from_xml(read_xml("recipes").root.children[1])
recipe.should be_valid
recipe.calculate_fg.should == 1.016
end
end

0 comments on commit c785dde

Please sign in to comment.