punky_brewster 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/punky_brewster.rb +2 -0
- data/lib/punky_brewster/beer_list.rb +13 -0
- data/lib/punky_brewster/beer_list_response.rb +7 -7
- data/lib/punky_brewster/beer_repository.rb +11 -0
- data/lib/punky_brewster/cli.rb +2 -2
- data/lib/punky_brewster/server.rb +8 -4
- data/lib/punky_brewster/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '0812d42f527539d57072dcff9131ac306ebbbdc69eb6e21609e66d2a543183c1'
|
4
|
+
data.tar.gz: '08dca616a829a548b9766da45f71d00dcb1a1e90d8a305afd189aedbd966f58f'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90806764c5d4c56a5e30fb5bdc7751337ae4dc56528e530579aea51a8429c8270edf07fcfadfd803dea5b965711e12530f2e503e7b693a35b1bd6bdc0d127a79
|
7
|
+
data.tar.gz: 1f18d33364ed25d48fabc77cc00f58096e52352b95422a5e00c4fdebe67a905b1dee012ef5d250053bb5de5918882a80c779488a52c426e76b96a0af2e188bed
|
data/lib/punky_brewster.rb
CHANGED
@@ -11,23 +11,23 @@ module PunkyBrewster
|
|
11
11
|
def beers
|
12
12
|
@beers ||= begin
|
13
13
|
content = document.at_css('#content')
|
14
|
-
|
14
|
+
list = []
|
15
15
|
|
16
16
|
content.traverse do |node|
|
17
17
|
if node.name == 'h2'
|
18
|
-
|
18
|
+
list << Beer.new
|
19
19
|
# Includes non-breaking spaces
|
20
|
-
|
20
|
+
list.last.name = node.text.upcase.gsub(/[\s\u00A0]+/, ' ')
|
21
21
|
elsif node.name == 'img'
|
22
|
-
|
22
|
+
list.last.image_url = IMAGE_URL_BASE + node[:src]
|
23
23
|
elsif price = node.text.scan(/^\$(\d+\.\d+)\/L$/).flatten.first
|
24
|
-
|
24
|
+
list.last.price = price.to_f
|
25
25
|
elsif abv = node.text.scan(/(\d+\.\d+)\s*%/).flatten.first
|
26
|
-
|
26
|
+
list.last.abv = abv.to_f
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
BeerList.new(list.select(&:valid?))
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
data/lib/punky_brewster/cli.rb
CHANGED
@@ -17,7 +17,7 @@ module PunkyBrewster
|
|
17
17
|
def list
|
18
18
|
show_abv_per_dollar = options[:holla_for_dollar] || options[:cheapskate]
|
19
19
|
|
20
|
-
beers =
|
20
|
+
beers = BeerRepository.list
|
21
21
|
|
22
22
|
if options[:holla_for_dollar]
|
23
23
|
sorted = beers.sort { |a, b| b.abv_per_dollar <=> a.abv_per_dollar }
|
@@ -26,7 +26,7 @@ module PunkyBrewster
|
|
26
26
|
end
|
27
27
|
|
28
28
|
rows = sorted.map do |beer|
|
29
|
-
row = [beer.name, "$%0.2f/L" % beer.price, "%0.1f
|
29
|
+
row = [beer.name, "$%0.2f/L" % beer.price, "%0.1f%%" % beer.abv]
|
30
30
|
row << ("%0.2f%%/$" % beer.abv_per_dollar) if show_abv_per_dollar
|
31
31
|
row
|
32
32
|
end
|
@@ -3,13 +3,12 @@ require 'punky_brewster'
|
|
3
3
|
|
4
4
|
module PunkyBrewster
|
5
5
|
class Server
|
6
|
-
|
6
|
+
|
7
|
+
def call(env)
|
7
8
|
headers = { 'Content-Type' => 'application/json' }
|
8
9
|
|
9
10
|
begin
|
10
|
-
|
11
|
-
beers_properties = beers.map(&:to_h)
|
12
|
-
body = JSON.generate(beers_properties)
|
11
|
+
body = BeerRepository.list.to_json
|
13
12
|
status = 200
|
14
13
|
rescue => error
|
15
14
|
body = JSON.generate(error: "#{error.class}: #{error}")
|
@@ -18,5 +17,10 @@ module PunkyBrewster
|
|
18
17
|
|
19
18
|
[status, headers, [body]]
|
20
19
|
end
|
20
|
+
|
21
|
+
def self.call(env)
|
22
|
+
self.new.call(env)
|
23
|
+
end
|
24
|
+
|
21
25
|
end
|
22
26
|
end
|
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.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pete Nicholls
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -156,8 +156,10 @@ files:
|
|
156
156
|
- exe/punky_brewster
|
157
157
|
- lib/punky_brewster.rb
|
158
158
|
- lib/punky_brewster/beer.rb
|
159
|
+
- lib/punky_brewster/beer_list.rb
|
159
160
|
- lib/punky_brewster/beer_list_request.rb
|
160
161
|
- lib/punky_brewster/beer_list_response.rb
|
162
|
+
- lib/punky_brewster/beer_repository.rb
|
161
163
|
- lib/punky_brewster/cli.rb
|
162
164
|
- lib/punky_brewster/server.rb
|
163
165
|
- lib/punky_brewster/version.rb
|
@@ -182,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
184
|
version: '0'
|
183
185
|
requirements: []
|
184
186
|
rubyforge_project:
|
185
|
-
rubygems_version: 2.
|
187
|
+
rubygems_version: 2.7.6
|
186
188
|
signing_key:
|
187
189
|
specification_version: 4
|
188
190
|
summary: What's pouring at Punky Brewster?
|