brewery 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -1
- data/README.md +18 -0
- data/brewery.gemspec +3 -0
- data/lib/brewery.rb +4 -28
- data/lib/brewery/data/styleguide.dtd +110 -0
- data/lib/brewery/data/styleguide2008.xml +3259 -0
- data/lib/brewery/guides.rb +42 -0
- data/lib/brewery/priming.rb +23 -0
- data/lib/brewery/refractometer.rb +30 -0
- data/lib/brewery/version.rb +1 -1
- data/spec/brewery/guides_spec.rb +53 -0
- data/spec/brewery/priming_spec.rb +16 -0
- data/spec/brewery/refractometer_spec.rb +22 -0
- data/spec/spec_helper.rb +4 -5
- metadata +41 -4
- data/spec/refractometer_spec.rb +0 -33
@@ -0,0 +1,42 @@
|
|
1
|
+
module Brewery
|
2
|
+
def self.guides(name)
|
3
|
+
Brewery::Guides.const_get(name.capitalize).new
|
4
|
+
end
|
5
|
+
|
6
|
+
class Guides
|
7
|
+
class Bjcp
|
8
|
+
attr_accessor :styles
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@styles = load_xml
|
12
|
+
end
|
13
|
+
|
14
|
+
def find(args={})
|
15
|
+
styles.find {|v| v.id == args[:id]}
|
16
|
+
end
|
17
|
+
|
18
|
+
def load_xml
|
19
|
+
file = File.open(File.join(File.expand_path(File.dirname(__FILE__)), 'data', 'styleguide2008.xml'))
|
20
|
+
Nokogiri::XML(file).css("[type='beer']").css('subcategory').map {|xml| Style.new(xml)}
|
21
|
+
end
|
22
|
+
private :load_xml
|
23
|
+
end
|
24
|
+
|
25
|
+
class Style
|
26
|
+
STATS_METHODS = %w[og_low og_high fg_low fg_high ibu_low ibu_high srm_low srm_high abv_low abv_high]
|
27
|
+
|
28
|
+
attr_accessor :id, :name
|
29
|
+
|
30
|
+
def initialize(xml)
|
31
|
+
@id = xml.attr('id')
|
32
|
+
@name = xml.css('name').text
|
33
|
+
|
34
|
+
STATS_METHODS.each do |var|
|
35
|
+
define_singleton_method var.to_sym do
|
36
|
+
xml.css(var.gsub('_', ' ')).text.to_f
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Brewery
|
2
|
+
class Priming
|
3
|
+
attr_accessor :radius, :height
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
@radius = args[:radius]
|
7
|
+
@height = args[:height]
|
8
|
+
end
|
9
|
+
|
10
|
+
def volume_of_cylinder
|
11
|
+
((3.14 * @radius * @radius * @height) / 1000).round(3)
|
12
|
+
end
|
13
|
+
|
14
|
+
# TODO Config initializer to set the units
|
15
|
+
#
|
16
|
+
def total(args)
|
17
|
+
gr = args[:sugar]
|
18
|
+
sugar = (volume_of_cylinder * gr).round(3)
|
19
|
+
water = sugar * 3
|
20
|
+
return sugar, water
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Brewery
|
2
|
+
class Refractometer
|
3
|
+
attr_accessor :original_brix, :final_brix
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
@original_brix = args[:original_brix]
|
7
|
+
@final_brix = args[:final_brix]
|
8
|
+
end
|
9
|
+
|
10
|
+
def specific_gravity
|
11
|
+
1.000898 + (0.003859118*original_brix) + (0.00001370735*original_brix*original_brix) + (0.00000003742517*original_brix*original_brix*original_brix)
|
12
|
+
end
|
13
|
+
|
14
|
+
def final_gravity
|
15
|
+
1.001843 - (0.002318474*original_brix) - (0.000007775*original_brix*original_brix) - (0.000000034*original_brix*original_brix*original_brix) + (0.00574*final_brix) + (0.00003344*final_brix*final_brix) + (0.000000086*final_brix*final_brix*final_brix)
|
16
|
+
end
|
17
|
+
|
18
|
+
def index_of_refraction
|
19
|
+
1.33302 + (0.001427193*final_brix) + (0.000005791157*final_brix*final_brix)
|
20
|
+
end
|
21
|
+
|
22
|
+
def alcohol_by_weight
|
23
|
+
1017.5596 - (277.4*final_gravity) + index_of_refraction*((937.8135*index_of_refraction) - 1805.1228)
|
24
|
+
end
|
25
|
+
|
26
|
+
def alcohol_by_volume
|
27
|
+
alcohol_by_weight*(final_gravity/0.794)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/brewery/version.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Brewery::Guides do
|
4
|
+
context "BJCP Beer Style Guidelines" do
|
5
|
+
let(:guide) { Brewery.guides :bjcp }
|
6
|
+
|
7
|
+
describe ".styles" do
|
8
|
+
it "returns all styles" do
|
9
|
+
expect(guide.styles.count).to eql(80)
|
10
|
+
end
|
11
|
+
|
12
|
+
context "Basic data and Vital Statistics" do
|
13
|
+
let(:style) { guide.styles.first }
|
14
|
+
|
15
|
+
it { expect(style.name).to eq("Lite American Lager") }
|
16
|
+
it { expect(style.id).to eq("1A") }
|
17
|
+
|
18
|
+
it { expect(style.og_low).to eql(1.028) }
|
19
|
+
it { expect(style.og_high).to eql(1.040) }
|
20
|
+
|
21
|
+
it { expect(style.fg_low).to eql(0.998) }
|
22
|
+
it { expect(style.fg_high).to eql(1.008) }
|
23
|
+
|
24
|
+
it { expect(style.ibu_low).to eql(8.0) }
|
25
|
+
it { expect(style.ibu_high).to eql(12.0) }
|
26
|
+
|
27
|
+
it { expect(style.srm_low).to eql(2.0) }
|
28
|
+
it { expect(style.srm_high).to eql(3.0) }
|
29
|
+
|
30
|
+
it { expect(style.abv_low).to eql(2.8) }
|
31
|
+
it { expect(style.abv_high).to eql(4.2) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".find" do
|
36
|
+
context "when the style is found" do
|
37
|
+
let(:result) { guide.find(id: '14B') }
|
38
|
+
|
39
|
+
it "returns the style" do
|
40
|
+
expect(result.name).to eq('American IPA')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when the style is not found" do
|
45
|
+
let(:result) { guide.find(id: 'xxx') }
|
46
|
+
|
47
|
+
it "returns nil" do
|
48
|
+
expect(result).to be_nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Brewery::Priming do
|
4
|
+
let(:priming) { described_class.new(radius: 8.5, height: 11.5) }
|
5
|
+
|
6
|
+
it { expect(priming.volume_of_cylinder).to eql(2.609) }
|
7
|
+
|
8
|
+
describe "#total" do
|
9
|
+
it "returns total of sugar and water" do
|
10
|
+
sugar, water = priming.total(sugar: 6)
|
11
|
+
|
12
|
+
expect(sugar).to eql(15.654)
|
13
|
+
expect(water).to eql(46.962)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Brewery::Refractometer do
|
4
|
+
context "Brix to Specific Gravity" do
|
5
|
+
let(:tool) { described_class.new(original_brix: 17) }
|
6
|
+
|
7
|
+
describe "#specific_gravity" do
|
8
|
+
it "should return the specific gravity of the original brix" do
|
9
|
+
expect(tool.specific_gravity).to eql(1.0706483000102098)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "Corrected Final Gravity & ABV% by Brix" do
|
15
|
+
let(:tool) { described_class.new(original_brix: 17, final_brix: 7.5) }
|
16
|
+
|
17
|
+
it { expect(tool.final_gravity).to eql(1.0049822062500002) }
|
18
|
+
it { expect(tool.index_of_refraction).to eql(1.34404970008125) }
|
19
|
+
it { expect(tool.alcohol_by_weight).to eql(6.734352775327011) }
|
20
|
+
it { expect(tool.alcohol_by_volume).to eql(8.523809458203969) }
|
21
|
+
end
|
22
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -10,10 +10,9 @@ RSpec.configure do |config|
|
|
10
10
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
11
|
config.run_all_when_everything_filtered = true
|
12
12
|
config.filter_run :focus
|
13
|
-
|
14
|
-
# Run specs in random order to surface order dependencies. If you find an
|
15
|
-
# order dependency and want to debug it, you can fix the order by providing
|
16
|
-
# the seed, which is printed after each run.
|
17
|
-
# --seed 1234
|
18
13
|
config.order = 'random'
|
14
|
+
|
15
|
+
config.expect_with :rspec do |c|
|
16
|
+
c.syntax = :expect
|
17
|
+
end
|
19
18
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brewery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesus Lopes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.6.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +80,20 @@ dependencies:
|
|
66
80
|
- - ~>
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '2.14'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: fuubar
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
description: Tools for Homebrewing
|
70
98
|
email:
|
71
99
|
- jlopes@zigotto.com.br
|
@@ -81,8 +109,15 @@ files:
|
|
81
109
|
- Rakefile
|
82
110
|
- brewery.gemspec
|
83
111
|
- lib/brewery.rb
|
112
|
+
- lib/brewery/data/styleguide.dtd
|
113
|
+
- lib/brewery/data/styleguide2008.xml
|
114
|
+
- lib/brewery/guides.rb
|
115
|
+
- lib/brewery/priming.rb
|
116
|
+
- lib/brewery/refractometer.rb
|
84
117
|
- lib/brewery/version.rb
|
85
|
-
- spec/
|
118
|
+
- spec/brewery/guides_spec.rb
|
119
|
+
- spec/brewery/priming_spec.rb
|
120
|
+
- spec/brewery/refractometer_spec.rb
|
86
121
|
- spec/spec_helper.rb
|
87
122
|
homepage: ''
|
88
123
|
licenses:
|
@@ -109,6 +144,8 @@ signing_key:
|
|
109
144
|
specification_version: 4
|
110
145
|
summary: Tools for Homebrewing
|
111
146
|
test_files:
|
112
|
-
- spec/
|
147
|
+
- spec/brewery/guides_spec.rb
|
148
|
+
- spec/brewery/priming_spec.rb
|
149
|
+
- spec/brewery/refractometer_spec.rb
|
113
150
|
- spec/spec_helper.rb
|
114
151
|
has_rdoc:
|
data/spec/refractometer_spec.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Brewery::Refractometer do
|
4
|
-
context "Brix to Specific Gravity" do
|
5
|
-
let(:tool) { Brewery::Refractometer.new(original_brix: 17) }
|
6
|
-
|
7
|
-
describe "#specific_gravity" do
|
8
|
-
it "should return the specific gravity of the original brix" do
|
9
|
-
tool.specific_gravity.should eql(1.0706483000102098)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context "Corrected Final Gravity & ABV% by Brix" do
|
15
|
-
let(:tool) { Brewery::Refractometer.new(original_brix: 17, final_brix: 7.5) }
|
16
|
-
|
17
|
-
describe "#final_gravity" do
|
18
|
-
it { tool.final_gravity.should eql(1.0049822062500002) }
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#index_of_refraction" do
|
22
|
-
it { tool.index_of_refraction.should eql(1.34404970008125) }
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "#alcohol_by_weight" do
|
26
|
-
it { tool.alcohol_by_weight.should eql(6.734352775327011) }
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#alcohol_by_volume" do
|
30
|
-
it { tool.alcohol_by_volume.should eql(8.523809458203969) }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|