brewery 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94f46fefa47a750e999b971b6a555d099579d48d
4
- data.tar.gz: 1c4e9b5f36e76e586cf61ee1926d14781b69fc70
3
+ metadata.gz: eba6fb570f7ef71907692735ce9ce630c604c6ba
4
+ data.tar.gz: 22ed58c2831729dc45db58193ec2e57bc7b8930d
5
5
  SHA512:
6
- metadata.gz: 42102e7765da445db4c9729d0270f6395471d2a7f9064d6d76e3757ce46ad0de91719017cc2c9fa85f59ea9e94f616390d0e70ad2298e97975e521db9b8cc2f6
7
- data.tar.gz: c823813422b28b6359ef572ad3eeed4b8632c120df05d945f2111b7274d912c1a0c2fb4675c7d31f745a8ef052d86a1980717bab8ad1bc1d9c2313fe13d83bbb
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
- search = guide.find(id: '14B')
72
- search.name
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
 
@@ -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
- @styles = load_xml
7
+ @categories = load_categories
8
+ @styles = load_styles
8
9
  end
9
10
 
10
- def find(args={})
11
- styles.find {|v| v.id == args[: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 load_xml
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']").css('subcategory').map {|xml| Style.new(xml)}
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
@@ -1,3 +1,3 @@
1
1
  module Brewery
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -32,9 +32,22 @@ describe Brewery::Guides do
32
32
  end
33
33
  end
34
34
 
35
- describe ".find" do
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.find(id: '14B') }
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.find(id: 'xxx') }
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.0
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-21 00:00:00.000000000 Z
11
+ date: 2013-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri