beer_in_the_evening 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/beer_in_the_evening.gemspec +1 -0
- data/bin/bite +32 -0
- data/lib/beer_in_the_evening/search.rb +15 -11
- data/lib/beer_in_the_evening/version.rb +1 -1
- metadata +29 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4e465b2059ff3fea2bf15c8beee1a391885467fb
|
4
|
+
data.tar.gz: ea7d2d9416a18b58c41e12635f47c7418e106142
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9dbcac1fe3813b633b565937b9c4e62cead4a55a88b35cef96a79e5058eec29c44ae8e9b989978c0c4de5144e6d013fa5440bdc2152c80cbaa4b8811a25b2b1d
|
7
|
+
data.tar.gz: 25411ef566fd3f40ddb4ddbee4a87e80793209822e183ba8424be49e067185446e16c12763a66358826bf81dbbfce4d5015516843b2481a4944918ce071fac3c
|
data/beer_in_the_evening.gemspec
CHANGED
data/bin/bite
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'beer_in_the_evening'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
require 'logger'
|
7
|
+
|
8
|
+
search = BeerInTheEvening::Search.new
|
9
|
+
|
10
|
+
OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: bite [options]"
|
12
|
+
|
13
|
+
opts.on("--minimum RATING", "Minimum rating to accept") do |r|
|
14
|
+
search.minimum_rating = r.to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on("--results NUMBER", "Number of results to return") do |r|
|
18
|
+
search.maximum_results = r.to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("-p", "--postcode POSTCODE", "Select near postcode") do |p|
|
22
|
+
search.postcode = p
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on("-r", "--random", "Sort results randomly") do |r|
|
26
|
+
search.sort_by = proc { |r| rand }
|
27
|
+
end
|
28
|
+
end.parse!
|
29
|
+
|
30
|
+
search.each do |pub|
|
31
|
+
puts pub.to_s
|
32
|
+
end
|
@@ -16,9 +16,12 @@ module BeerInTheEvening
|
|
16
16
|
attr_accessor :maximum_results
|
17
17
|
|
18
18
|
attr_accessor :logger
|
19
|
+
attr_accessor :sort_by
|
19
20
|
|
20
21
|
def initialize options = {}
|
21
22
|
self.logger = options[:logger] || NullLogger.instance
|
23
|
+
self.sort_by = proc { |r| -r.rating }
|
24
|
+
self.maximum_results = 100
|
22
25
|
end
|
23
26
|
|
24
27
|
def number_of_results
|
@@ -28,24 +31,25 @@ module BeerInTheEvening
|
|
28
31
|
|
29
32
|
def each &block
|
30
33
|
current_page = 0
|
31
|
-
|
34
|
+
results = []
|
32
35
|
loop do
|
33
36
|
logger.debug "Finding next set of results"
|
34
|
-
|
35
|
-
break if
|
37
|
+
page_results = results_on_page current_page
|
38
|
+
break if page_results.empty?
|
36
39
|
if maximum_results
|
37
|
-
while
|
38
|
-
logger.debug "Trimming results. Max = #{maximum_results}, Current = #{
|
39
|
-
|
40
|
+
while results.size + page_results.size > maximum_results do
|
41
|
+
logger.debug "Trimming results. Max = #{maximum_results}, Current = #{results.size + page_results.size}"
|
42
|
+
page_results.pop
|
40
43
|
end
|
41
44
|
end
|
42
|
-
logger.debug "Yielding #{results.size} pubs to client"
|
43
|
-
results.each &block
|
44
|
-
logger.debug "Client code finished"
|
45
45
|
current_page += 1
|
46
|
-
|
47
|
-
break if maximum_results &&
|
46
|
+
results += page_results
|
47
|
+
break if maximum_results && results.size >= maximum_results
|
48
48
|
end
|
49
|
+
logger.debug "Yielding #{results.size} pubs to client"
|
50
|
+
results.sort_by! &sort_by
|
51
|
+
results.each &block
|
52
|
+
logger.debug "Client code finished"
|
49
53
|
end
|
50
54
|
include Enumerable
|
51
55
|
|
metadata
CHANGED
@@ -1,60 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beer_in_the_evening
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Craig R Webster
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-10-15 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: nokogiri
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: null_logger
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
44
53
|
- !ruby/object:Gem::Version
|
45
54
|
version: '0'
|
46
55
|
description: Search over the Beer In The Evening site looking for suitable pubs
|
47
56
|
email:
|
48
57
|
- craig@barkingiguana.com
|
49
|
-
executables:
|
58
|
+
executables:
|
59
|
+
- bite
|
50
60
|
extensions: []
|
51
61
|
extra_rdoc_files: []
|
52
62
|
files:
|
53
|
-
- .gitignore
|
63
|
+
- ".gitignore"
|
54
64
|
- Gemfile
|
55
65
|
- README.md
|
56
66
|
- Rakefile
|
57
67
|
- beer_in_the_evening.gemspec
|
68
|
+
- bin/bite
|
58
69
|
- examples/near_holborn.rb
|
59
70
|
- examples/near_postcode.rb
|
60
71
|
- lib/beer_in_the_evening.rb
|
@@ -65,26 +76,25 @@ files:
|
|
65
76
|
- lib/beer_in_the_evening/version.rb
|
66
77
|
homepage: ''
|
67
78
|
licenses: []
|
79
|
+
metadata: {}
|
68
80
|
post_install_message:
|
69
81
|
rdoc_options: []
|
70
82
|
require_paths:
|
71
83
|
- lib
|
72
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
85
|
requirements:
|
75
|
-
- -
|
86
|
+
- - ">="
|
76
87
|
- !ruby/object:Gem::Version
|
77
88
|
version: '0'
|
78
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
90
|
requirements:
|
81
|
-
- -
|
91
|
+
- - ">="
|
82
92
|
- !ruby/object:Gem::Version
|
83
93
|
version: '0'
|
84
94
|
requirements: []
|
85
95
|
rubyforge_project: beer_in_the_evening
|
86
|
-
rubygems_version:
|
96
|
+
rubygems_version: 2.2.2
|
87
97
|
signing_key:
|
88
|
-
specification_version:
|
98
|
+
specification_version: 4
|
89
99
|
summary: Is it pub time?
|
90
100
|
test_files: []
|