punky_brewster 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/punky_brewster/beer_list_request.rb +16 -0
- data/lib/punky_brewster/beer_list_response.rb +39 -0
- data/lib/punky_brewster/cli.rb +1 -21
- data/lib/punky_brewster/version.rb +1 -1
- data/lib/punky_brewster.rb +3 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10745cdefe9b6de234e68aa53135e5bba7d89c41
|
4
|
+
data.tar.gz: 5c517479b5e736ac8c6d0f687be46e62fd2e89a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d698a5e0379d6b26d5ab8f726db3d227b24e11bb1eaeecf8fcf75ca99507b104cd719219782e4f46a8bc858926f77e4bc90ef5e6047f95ffd4c3f846b65b12c
|
7
|
+
data.tar.gz: ad7846f329c892c5f834e88ed27f258d2ecc0277fbb22d8fc2184c0a12fd3c587bb794fa80d85445cce46168dd905efcbea3a5831bfcda91b2c4338f258f2676
|
data/README.md
CHANGED
@@ -23,7 +23,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
23
23
|
|
24
24
|
## Contributing
|
25
25
|
|
26
|
-
1. Fork it ( https://github.com/
|
26
|
+
1. Fork it ( https://github.com/Aupajo/punky_brewster/fork )
|
27
27
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
28
28
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
29
29
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "net/http"
|
2
|
+
|
3
|
+
module PunkyBrewster
|
4
|
+
class BeerListRequest
|
5
|
+
URL = "http://www.punkybrewster.co.nz"
|
6
|
+
|
7
|
+
def response
|
8
|
+
raw_response = Net::HTTP.get_response(URI(URL))
|
9
|
+
BeerListResponse.new(raw_response)
|
10
|
+
end
|
11
|
+
|
12
|
+
def beers
|
13
|
+
response.beers
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module PunkyBrewster
|
2
|
+
class BeerListResponse
|
3
|
+
def initialize(raw_response)
|
4
|
+
@raw_response = raw_response
|
5
|
+
end
|
6
|
+
|
7
|
+
def beers
|
8
|
+
@beers ||= begin
|
9
|
+
content = document.at_css('#content')
|
10
|
+
divide = content.at_css('.styled-hr')
|
11
|
+
past_divide = false
|
12
|
+
beer_list = []
|
13
|
+
|
14
|
+
content.traverse do |node|
|
15
|
+
past_divide = true if node == divide
|
16
|
+
next unless past_divide
|
17
|
+
|
18
|
+
if node.name == 'h2'
|
19
|
+
beer_list << Beer.new
|
20
|
+
# Includes non-breaking spaces
|
21
|
+
beer_list.last.name = node.text.upcase.gsub(/[\s\u00A0]+/, ' ')
|
22
|
+
elsif price = node.text.scan(/^\$(\d+\.\d+)\/L$/).flatten.first
|
23
|
+
beer_list.last.price = price.to_f
|
24
|
+
elsif abv = node.text.scan(/(\d+\.\d+)\s*%/).flatten.first
|
25
|
+
beer_list.last.abv = abv.to_f
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
beer_list
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def document
|
36
|
+
@document ||= Nokogiri::HTML(@raw_response.body)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/punky_brewster/cli.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require "thor"
|
2
2
|
require "punky_brewster"
|
3
|
-
require "ostruct"
|
4
3
|
require "nokogiri"
|
5
4
|
require "open-uri"
|
6
5
|
|
@@ -15,26 +14,7 @@ module PunkyBrewster
|
|
15
14
|
|
16
15
|
desc "list", "Show current beer list"
|
17
16
|
def list
|
18
|
-
|
19
|
-
document = Nokogiri::HTML(response)
|
20
|
-
content = document.at_css('#content')
|
21
|
-
divide = content.at_css('.styled-hr')
|
22
|
-
past_divide = false
|
23
|
-
beers = []
|
24
|
-
|
25
|
-
content.traverse do |node|
|
26
|
-
past_divide = true if node == divide
|
27
|
-
next unless past_divide
|
28
|
-
|
29
|
-
if node.name == 'h2'
|
30
|
-
beers << OpenStruct.new
|
31
|
-
beers.last.name = node.text.upcase.gsub(/\s+/, ' ')
|
32
|
-
elsif price = node.text.scan(/^\$(\d+\.\d+)\/L$/).flatten.first
|
33
|
-
beers.last.price = price.to_f
|
34
|
-
elsif abv = node.text.scan(/(\d+\.\d+)\s*%/).flatten.first
|
35
|
-
beers.last.abv = abv.to_f
|
36
|
-
end
|
37
|
-
end
|
17
|
+
beers = BeerListRequest.new.beers
|
38
18
|
|
39
19
|
rows = beers.sort_by(&:name).map do |beer|
|
40
20
|
[beer.name, "$%0.2f/L" % beer.price, "%0.1f%" % beer.abv]
|
data/lib/punky_brewster.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: punky_brewster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pete Nicholls
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -127,6 +127,8 @@ files:
|
|
127
127
|
- bin/setup
|
128
128
|
- exe/punky_brewster
|
129
129
|
- lib/punky_brewster.rb
|
130
|
+
- lib/punky_brewster/beer_list_request.rb
|
131
|
+
- lib/punky_brewster/beer_list_response.rb
|
130
132
|
- lib/punky_brewster/cli.rb
|
131
133
|
- lib/punky_brewster/version.rb
|
132
134
|
- punky_brewster.gemspec
|