brewery 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,7 +28,7 @@ module Brewery
28
28
  end
29
29
 
30
30
  def file
31
- file = File.open(File.join(File.expand_path(File.dirname(__FILE__)), 'data', 'styleguide2008.xml'))
31
+ file = Utils.open_file('styleguide2008.xml')
32
32
  Nokogiri::XML(file).css("[type='beer']")
33
33
  end
34
34
  end
@@ -0,0 +1,39 @@
1
+ module Brewery
2
+ class Ingredient
3
+ module InstanceMethods
4
+ include Enumerable
5
+
6
+ def initialize(name)
7
+ self.file = Utils.open_file("#{name}.json").read
8
+ end
9
+
10
+ def each
11
+ return to_enum unless block_given?
12
+
13
+ @collection.each {|element| yield(Hashie::Mash.new(element)) }
14
+ end
15
+
16
+ def find_by(name: nil)
17
+ self.find_all {|v| v.name =~ /#{name}/i}
18
+ end
19
+
20
+ private
21
+
22
+ def file=(file)
23
+ @collection = JSON.parse(file)["Ingredients"]
24
+ end
25
+ end
26
+
27
+ class Fermentables
28
+ include InstanceMethods
29
+ end
30
+
31
+ class Hops
32
+ include InstanceMethods
33
+ end
34
+
35
+ class Yeasts
36
+ include InstanceMethods
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,9 @@
1
+ module Brewery
2
+ class Utils
3
+ class << self
4
+ def open_file(file)
5
+ File.open(File.join(File.expand_path(File.dirname(__FILE__)), 'data', file))
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Brewery
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Brewery::Ingredient do
4
+ context "Fermentables" do
5
+ let(:fermentables) { Brewery.ingredients :fermentables }
6
+
7
+ it { expect(fermentables.count).to eql(187) }
8
+
9
+ context "fermentable data" do
10
+ let(:fermentable) { fermentables.first }
11
+
12
+ it { expect(fermentable.description).to include('Amber malt is a roasted malt that is used in mild ales') }
13
+ it { expect(fermentable.color).to eq('22.000000') }
14
+ it { expect(fermentable.moisture).to eq('3.000000') }
15
+ it { expect(fermentable.extract).to eq('80.000000') }
16
+ it { expect(fermentable.name).to eq('Australian Amber Malt') }
17
+ end
18
+
19
+ context "search" do
20
+ let(:search) { fermentables.find_by(name: 'pale') }
21
+
22
+ it { expect(search.count).to eql(8) }
23
+ end
24
+ end
25
+
26
+ context "Hops" do
27
+ let(:hops) { Brewery.ingredients :hops }
28
+
29
+ it { expect(hops.count).to eql(85) }
30
+
31
+ context "hops data" do
32
+ let(:hop) { hops.first }
33
+
34
+ it { expect(hop.description).to include('Exciting hop variety that was new in 2010 from Australia.') }
35
+ it { expect(hop.alpha).to eq('15.000000') }
36
+ it { expect(hop.name).to eq('Australian Galaxy') }
37
+ end
38
+
39
+ context "search" do
40
+ let(:search) { hops.find_by(name: 'mag') }
41
+
42
+ it { expect(search.count).to eql(2) }
43
+ end
44
+ end
45
+
46
+ context "Yeast" do
47
+ let(:yeasts) { Brewery.ingredients :yeasts }
48
+
49
+ it { expect(yeasts.count).to eql(208) }
50
+
51
+ context "yeast data" do
52
+ let(:yeast) { yeasts.first }
53
+
54
+ it { expect(yeast.description).to include('General purpose top fermenting strain.') }
55
+ it { expect(yeast.yeast_type).to eq('Liquid') }
56
+ it { expect(yeast.beer_type).to eq('Ale') }
57
+ it { expect(yeast.attenuation).to eq('75.000000') }
58
+ it { expect(yeast.name).to eq('Brewferm Ale Yeast') }
59
+ end
60
+
61
+ context "search" do
62
+ let(:search) { yeasts.find_by(name: '05') }
63
+
64
+ it { expect(search.count).to eql(7) }
65
+ end
66
+ end
67
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brewery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
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-09-22 00:00:00.000000000 Z
11
+ date: 2013-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: hashie
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.5
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -110,13 +124,19 @@ files:
110
124
  - bjcp-categories.md
111
125
  - brewery.gemspec
112
126
  - lib/brewery.rb
127
+ - lib/brewery/data/fermentables.json
128
+ - lib/brewery/data/hops.json
113
129
  - lib/brewery/data/styleguide.dtd
114
130
  - lib/brewery/data/styleguide2008.xml
131
+ - lib/brewery/data/yeasts.json
115
132
  - lib/brewery/guides.rb
133
+ - lib/brewery/ingredient.rb
116
134
  - lib/brewery/priming.rb
117
135
  - lib/brewery/refractometer.rb
136
+ - lib/brewery/utils.rb
118
137
  - lib/brewery/version.rb
119
138
  - spec/brewery/guides_spec.rb
139
+ - spec/brewery/ingredient_spec.rb
120
140
  - spec/brewery/priming_spec.rb
121
141
  - spec/brewery/refractometer_spec.rb
122
142
  - spec/spec_helper.rb
@@ -146,6 +166,7 @@ specification_version: 4
146
166
  summary: Tools for Homebrewing
147
167
  test_files:
148
168
  - spec/brewery/guides_spec.rb
169
+ - spec/brewery/ingredient_spec.rb
149
170
  - spec/brewery/priming_spec.rb
150
171
  - spec/brewery/refractometer_spec.rb
151
172
  - spec/spec_helper.rb