punky_brewster 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -18
- data/lib/punky_brewster/beer.rb +7 -0
- data/lib/punky_brewster/beer_list_response.rb +4 -0
- data/lib/punky_brewster/cli.rb +14 -3
- data/lib/punky_brewster/version.rb +1 -1
- data/lib/punky_brewster.rb +1 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8a9177571a0dcd323267ab86c302822074fad2f
|
4
|
+
data.tar.gz: 47417879ff9929663329a0833e93a2b240b6c3b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 440fe7236b3791f5c252ade1d65aebdbde2e5688a907c564a3dcd5c8e9fc07e148eee268f6974d0716252170456f0bdba25bcb5f60137b3e4bfb0c79834c8a9b
|
7
|
+
data.tar.gz: 59b547292fbfb7b3f619d7e2e85d1f02d739baf4dcc09ddae74c852d14cc478ace63e095ac019ab6b48a4b65bfe632c3f558274b20e2b9a03fb47c3b29935e58
|
data/README.md
CHANGED
@@ -8,6 +8,8 @@ What's on tap?
|
|
8
8
|
|
9
9
|
## Command line tool
|
10
10
|
|
11
|
+
List beers:
|
12
|
+
|
11
13
|
$ punky_brewster
|
12
14
|
8 WIRED HOPWIRED $16.00/L 7.3%
|
13
15
|
ALL CHIEFS , NO INDIANS $14.00/L 6.0%
|
@@ -15,19 +17,24 @@ What's on tap?
|
|
15
17
|
DALES ESB (EXTRA SPECIAL BITTER) $14.00/L 5.6%
|
16
18
|
...
|
17
19
|
|
20
|
+
Sort beers (can be sorted by `price`, `abv`, or `abv_per_dollar`):
|
21
|
+
|
18
22
|
$ punky_brewster --sort price
|
19
23
|
CROUCHER LOW RIDER IPA $12.00/L 2.7%
|
20
24
|
TUATARA ITI AMERICAN PALE ALE $12.50/L 5.8%
|
21
25
|
MUSSEL INN CAPTAIN COOKER $12.50/L 5.7%
|
22
26
|
VALKYRIE FRIGG RED PILSENER $13.50/L 5.0%
|
27
|
+
...
|
23
28
|
|
29
|
+
List beers sorted by most ABV per dollar:
|
30
|
+
|
31
|
+
$ punky_brewster --holla-for-dollar
|
32
|
+
MIKE'S VANILLA COFFEE PORTER $16.00/L 8.0% 0.50%/$
|
33
|
+
RAINDOGS OXYMORON BLACK IPA $14.50/L 7.0% 0.48%/$
|
34
|
+
GOLDEN EAGLE BIG YANK $16.00/L 7.5% 0.47%/$
|
35
|
+
MUSSEL INN CAPTAIN COOKER $12.50/L 5.7% 0.46%/$
|
36
|
+
...
|
24
37
|
|
25
|
-
$ punky_brewster --sort abv
|
26
|
-
CROUCHER LOW RIDER IPA $12.00/L 2.7%
|
27
|
-
RENAISSANCE PARADOX PILSENER $14.00/L 4.0%
|
28
|
-
GARAGE PROJECT HAPI DAZE $14.00/L 4.2%
|
29
|
-
GOLDEN ALE FRESH HOP $16.00/L 4.5%
|
30
|
-
INVERCARGILL PITCHBLACK STOUT $13.50/L 4.5%
|
31
38
|
|
32
39
|
## Ruby Library
|
33
40
|
|
@@ -45,18 +52,6 @@ require 'punky_brewster/server'
|
|
45
52
|
run PunkyBrewster::Server
|
46
53
|
```
|
47
54
|
|
48
|
-
```http
|
49
|
-
$ curl -i localhost:9292
|
50
|
-
|
51
|
-
HTTP/1.1 200 OK
|
52
|
-
Content-Type: application/json
|
53
|
-
Transfer-Encoding: chunked
|
54
|
-
Connection: close
|
55
|
-
Server: thin
|
56
|
-
|
57
|
-
[{"name":"EPIC PALE ALE","price":14.0,"abv":5.4},{"name":"8 WIRED HOPWIRED","price":16.0,"abv":7.3},{"name":"MUSSEL INN CAPTAIN COOKER","price":12.5,"abv":5.7},{"name":"FUNK ESTATE NZPA FRESH HOP","price":16.0,"abv":5.5},{"name":"INVERCARGILL PITCHBLACK STOUT","price":13.5,"abv":4.5},{"name":"GOLDEN EAGLE BIG YANK","price":16.0,"abv":7.5},{"name":"RENAISSANCE PARADOX PILSENER","price":14.0,"abv":4.0}]
|
58
|
-
```
|
59
|
-
|
60
55
|
Mount alongside other Rack apps (Rails, Sinatra, etc.):
|
61
56
|
|
62
57
|
```ruby
|
@@ -73,6 +68,20 @@ use Rack::JSONP
|
|
73
68
|
run PunkyBrewster::Server
|
74
69
|
```
|
75
70
|
|
71
|
+
Response:
|
72
|
+
|
73
|
+
```json
|
74
|
+
[
|
75
|
+
{
|
76
|
+
"name": "EPIC PALE ALE",
|
77
|
+
"price": 14.0,
|
78
|
+
"abv": 5.4,
|
79
|
+
"image_url": "http://www.punkybrewster.co.nz/uploads/..."
|
80
|
+
},
|
81
|
+
...
|
82
|
+
]
|
83
|
+
```
|
84
|
+
|
76
85
|
## Development
|
77
86
|
|
78
87
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -2,6 +2,8 @@ require "nokogiri"
|
|
2
2
|
|
3
3
|
module PunkyBrewster
|
4
4
|
class BeerListResponse
|
5
|
+
IMAGE_URL_BASE = 'http://www.punkybrewster.co.nz'
|
6
|
+
|
5
7
|
def initialize(raw_response)
|
6
8
|
@raw_response = raw_response
|
7
9
|
end
|
@@ -21,6 +23,8 @@ module PunkyBrewster
|
|
21
23
|
beer_list << Beer.new
|
22
24
|
# Includes non-breaking spaces
|
23
25
|
beer_list.last.name = node.text.upcase.gsub(/[\s\u00A0]+/, ' ')
|
26
|
+
elsif node.name == 'img'
|
27
|
+
beer_list.last.image_url = IMAGE_URL_BASE + node[:src]
|
24
28
|
elsif price = node.text.scan(/^\$(\d+\.\d+)\/L$/).flatten.first
|
25
29
|
beer_list.last.price = price.to_f
|
26
30
|
elsif abv = node.text.scan(/(\d+\.\d+)\s*%/).flatten.first
|
data/lib/punky_brewster/cli.rb
CHANGED
@@ -11,13 +11,24 @@ module PunkyBrewster
|
|
11
11
|
end
|
12
12
|
|
13
13
|
desc "list", "Show current beer list"
|
14
|
-
method_option :sort, default: "name", enum: %w( name price abv )
|
14
|
+
method_option :sort, default: "name", enum: %w( name price abv abv_per_dollar )
|
15
|
+
method_option :cheapskate, type: :boolean, default: false
|
16
|
+
method_option :holla_for_dollar, type: :boolean, default: false
|
15
17
|
def list
|
18
|
+
show_abv_per_dollar = options[:holla_for_dollar] || options[:cheapskate]
|
19
|
+
|
16
20
|
beers = BeerListRequest.new.beers
|
17
|
-
|
21
|
+
|
22
|
+
if options[:holla_for_dollar]
|
23
|
+
sorted = beers.sort { |a, b| b.abv_per_dollar <=> a.abv_per_dollar }
|
24
|
+
else
|
25
|
+
sorted = beers.sort_by { |beer| beer.send(options[:sort]) }
|
26
|
+
end
|
18
27
|
|
19
28
|
rows = sorted.map do |beer|
|
20
|
-
[beer.name, "$%0.2f/L" % beer.price, "%0.1f%" % beer.abv]
|
29
|
+
row = [beer.name, "$%0.2f/L" % beer.price, "%0.1f%" % beer.abv]
|
30
|
+
row << ("%0.2f%%/$" % beer.abv_per_dollar) if show_abv_per_dollar
|
31
|
+
row
|
21
32
|
end
|
22
33
|
|
23
34
|
print_table rows
|
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.
|
4
|
+
version: 1.3.0
|
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-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- bin/setup
|
156
156
|
- exe/punky_brewster
|
157
157
|
- lib/punky_brewster.rb
|
158
|
+
- lib/punky_brewster/beer.rb
|
158
159
|
- lib/punky_brewster/beer_list_request.rb
|
159
160
|
- lib/punky_brewster/beer_list_response.rb
|
160
161
|
- lib/punky_brewster/cli.rb
|