brewery 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/README.md +11 -3
- data/lib/brewery/guides.rb +36 -7
- data/lib/brewery/version.rb +1 -1
- data/spec/brewery/guides_spec.rb +35 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eba6fb570f7ef71907692735ce9ce630c604c6ba
|
4
|
+
data.tar.gz: 22ed58c2831729dc45db58193ec2e57bc7b8930d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0218563361b6015244286a66d6dce7e85c56cb612323cae6992cd28f948bad88c61f35d41d84f9faafe22fba10fdae5e57e0dd7492debf3f586e110496d8d6cf
|
7
|
+
data.tar.gz: 156d072fad222efcdd7666e68d3924c7167b48f7bbedde13150342a85e8544888cedb5d4bc6c2a1f1d4c890d5b7873e6606635b8efb2a7f465c32ffb8cc68730
|
data/README.md
CHANGED
@@ -67,12 +67,20 @@ tool.alcohol_by_volume
|
|
67
67
|
```ruby
|
68
68
|
guide = Brewery.guides :bjcp
|
69
69
|
guide.styles
|
70
|
+
guide.categories
|
70
71
|
|
71
|
-
|
72
|
-
|
72
|
+
style = guide.find_style(id: '14B')
|
73
|
+
style.name
|
74
|
+
# => American IPA
|
75
|
+
|
76
|
+
category = guide.find_category(id: '14')
|
77
|
+
category.name
|
78
|
+
# => India Pale Ale(IPA)
|
79
|
+
|
80
|
+
category.styles
|
73
81
|
```
|
74
82
|
|
75
|
-
You can see the categories [here](bjcp-categories.md)
|
83
|
+
You can see the categories and styles [here](bjcp-categories.md)
|
76
84
|
|
77
85
|
#### Brewers Association (BA)
|
78
86
|
|
data/lib/brewery/guides.rb
CHANGED
@@ -1,21 +1,36 @@
|
|
1
1
|
module Brewery
|
2
2
|
class Guides
|
3
3
|
class Bjcp
|
4
|
-
attr_accessor :styles
|
4
|
+
attr_accessor :styles, :categories
|
5
5
|
|
6
6
|
def initialize
|
7
|
-
@
|
7
|
+
@categories = load_categories
|
8
|
+
@styles = load_styles
|
8
9
|
end
|
9
10
|
|
10
|
-
def
|
11
|
-
styles.find {|v| v.id ==
|
11
|
+
def find_style(id: nil)
|
12
|
+
styles.find {|v| v.id == id}
|
12
13
|
end
|
14
|
+
alias :find :find_style
|
13
15
|
|
14
|
-
def
|
16
|
+
def find_category(id: nil)
|
17
|
+
categories.find {|v| v.id == id}
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def load_categories
|
23
|
+
file.css('category').map {|xml| Category.new(xml) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def load_styles
|
27
|
+
file.css('subcategory').map {|xml| Style.new(xml) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def file
|
15
31
|
file = File.open(File.join(File.expand_path(File.dirname(__FILE__)), 'data', 'styleguide2008.xml'))
|
16
|
-
Nokogiri::XML(file).css("[type='beer']")
|
32
|
+
Nokogiri::XML(file).css("[type='beer']")
|
17
33
|
end
|
18
|
-
private :load_xml
|
19
34
|
end
|
20
35
|
|
21
36
|
class Style
|
@@ -34,5 +49,19 @@ module Brewery
|
|
34
49
|
end
|
35
50
|
end
|
36
51
|
end
|
52
|
+
|
53
|
+
class Category
|
54
|
+
attr_accessor :id, :name, :styles
|
55
|
+
|
56
|
+
def initialize(xml)
|
57
|
+
@id = xml.attr('id')
|
58
|
+
@name = xml.css('name').first.text
|
59
|
+
@styles = []
|
60
|
+
|
61
|
+
xml.css('subcategory').each do |style|
|
62
|
+
@styles << Style.new(style)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
37
66
|
end
|
38
67
|
end
|
data/lib/brewery/version.rb
CHANGED
data/spec/brewery/guides_spec.rb
CHANGED
@@ -32,9 +32,22 @@ describe Brewery::Guides do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe ".
|
35
|
+
describe ".categories" do
|
36
|
+
it "returns all categories" do
|
37
|
+
expect(guide.categories.count).to eql(23)
|
38
|
+
end
|
39
|
+
|
40
|
+
context "category data" do
|
41
|
+
let(:category) { guide.categories.first }
|
42
|
+
|
43
|
+
it { expect(category.name).to eq('Light Lager') }
|
44
|
+
it { expect(category.id).to eq('1') }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe ".find_style" do
|
36
49
|
context "when the style is found" do
|
37
|
-
let(:result) { guide.
|
50
|
+
let(:result) { guide.find_style(id: '14B') }
|
38
51
|
|
39
52
|
it "returns the style" do
|
40
53
|
expect(result.name).to eq('American IPA')
|
@@ -42,7 +55,26 @@ describe Brewery::Guides do
|
|
42
55
|
end
|
43
56
|
|
44
57
|
context "when the style is not found" do
|
45
|
-
let(:result) { guide.
|
58
|
+
let(:result) { guide.find_style(id: 'xxx') }
|
59
|
+
|
60
|
+
it "returns nil" do
|
61
|
+
expect(result).to be_nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe ".find_category" do
|
67
|
+
context "when the category is found" do
|
68
|
+
let(:result) { guide.find_category(id: '18') }
|
69
|
+
|
70
|
+
it { expect(result.id).to eql('18') }
|
71
|
+
it { expect(result.name).to eql('Belgian Strong Ale') }
|
72
|
+
|
73
|
+
it { expect(result.styles.count).to eql(5) }
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when the category is not found" do
|
77
|
+
let(:result) { guide.find_category(id: 666) }
|
46
78
|
|
47
79
|
it "returns nil" do
|
48
80
|
expect(result).to be_nil
|
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.
|
4
|
+
version: 0.1.1
|
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-
|
11
|
+
date: 2013-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|