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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6844c1b11fcbf2b357dcaa4d0642e9542d7d1911
4
- data.tar.gz: aa60da5f829ee4e2ac68c82ad393a77920c155e0
2
+ SHA256:
3
+ metadata.gz: '0812d42f527539d57072dcff9131ac306ebbbdc69eb6e21609e66d2a543183c1'
4
+ data.tar.gz: '08dca616a829a548b9766da45f71d00dcb1a1e90d8a305afd189aedbd966f58f'
5
5
  SHA512:
6
- metadata.gz: b5fa3e019bf34fb1c0cdaa1600c391c50d209b5aba74e25a402caa2b4baad08cd933fc6c6e30fe4120485ffb50940886be62bcd2b5d4620350f95321878c4bcd
7
- data.tar.gz: cf120db09b90f5c51d0a1c7d7df524eb685722219c11bf79c22fea35d3edbb98e17443b5580021293be26c61ed684f107340ae6800d4388044e575aacf41c664
6
+ metadata.gz: 90806764c5d4c56a5e30fb5bdc7751337ae4dc56528e530579aea51a8429c8270edf07fcfadfd803dea5b965711e12530f2e503e7b693a35b1bd6bdc0d127a79
7
+ data.tar.gz: 1f18d33364ed25d48fabc77cc00f58096e52352b95422a5e00c4fdebe67a905b1dee012ef5d250053bb5de5918882a80c779488a52c426e76b96a0af2e188bed
@@ -1,4 +1,6 @@
1
1
  require "punky_brewster/version"
2
2
  require "punky_brewster/beer"
3
+ require "punky_brewster/beer_repository"
4
+ require "punky_brewster/beer_list"
3
5
  require "punky_brewster/beer_list_request"
4
6
  require "punky_brewster/beer_list_response"
@@ -0,0 +1,13 @@
1
+ require 'json'
2
+
3
+ module PunkyBrewster
4
+ class BeerList < Array
5
+ def serialized_properties
6
+ map(&:to_h)
7
+ end
8
+
9
+ def to_json
10
+ JSON.generate(serialized_properties)
11
+ end
12
+ end
13
+ end
@@ -11,23 +11,23 @@ module PunkyBrewster
11
11
  def beers
12
12
  @beers ||= begin
13
13
  content = document.at_css('#content')
14
- beer_list = []
14
+ list = []
15
15
 
16
16
  content.traverse do |node|
17
17
  if node.name == 'h2'
18
- beer_list << Beer.new
18
+ list << Beer.new
19
19
  # Includes non-breaking spaces
20
- beer_list.last.name = node.text.upcase.gsub(/[\s\u00A0]+/, ' ')
20
+ list.last.name = node.text.upcase.gsub(/[\s\u00A0]+/, ' ')
21
21
  elsif node.name == 'img'
22
- beer_list.last.image_url = IMAGE_URL_BASE + node[:src]
22
+ list.last.image_url = IMAGE_URL_BASE + node[:src]
23
23
  elsif price = node.text.scan(/^\$(\d+\.\d+)\/L$/).flatten.first
24
- beer_list.last.price = price.to_f
24
+ list.last.price = price.to_f
25
25
  elsif abv = node.text.scan(/(\d+\.\d+)\s*%/).flatten.first
26
- beer_list.last.abv = abv.to_f
26
+ list.last.abv = abv.to_f
27
27
  end
28
28
  end
29
29
 
30
- beer_list.select(&:valid?)
30
+ BeerList.new(list.select(&:valid?))
31
31
  end
32
32
  end
33
33
 
@@ -0,0 +1,11 @@
1
+ module PunkyBrewster
2
+ class BeerRepository
3
+ def list
4
+ BeerListRequest.new.beers
5
+ end
6
+
7
+ def self.list(*args)
8
+ self.new(*args).list
9
+ end
10
+ end
11
+ end
@@ -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 = BeerListRequest.new.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%" % beer.abv]
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
- def self.call(env)
6
+
7
+ def call(env)
7
8
  headers = { 'Content-Type' => 'application/json' }
8
9
 
9
10
  begin
10
- beers = BeerListRequest.new.beers
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
@@ -1,3 +1,3 @@
1
1
  module PunkyBrewster
2
- VERSION = "1.3.1"
2
+ VERSION = "1.3.2"
3
3
  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.1
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: 2015-04-26 00:00:00.000000000 Z
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.4.5
187
+ rubygems_version: 2.7.6
186
188
  signing_key:
187
189
  specification_version: 4
188
190
  summary: What's pouring at Punky Brewster?