thirst 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +10 -1
- data/VERSION +1 -1
- data/lib/thirst/thirst_quencher.rb +32 -11
- data/spec/thirst_quencher_spec.rb +15 -0
- data/thirst.gemspec +2 -2
- metadata +15 -15
data/README.md
CHANGED
|
@@ -18,12 +18,21 @@ and if you want the pub closest to where your IP is thought to be you can
|
|
|
18
18
|
|
|
19
19
|
Pub.find
|
|
20
20
|
|
|
21
|
+
furthermore an options hash can give you the closest pub to an address of a point:
|
|
22
|
+
|
|
23
|
+
oliver = Pub.find :address => "Repslagargatan 6, Stockholm"
|
|
24
|
+
oliver.name.should == 'Oliver Twist'
|
|
25
|
+
|
|
26
|
+
amsterdam = Pub.find :point => [57.71, 11.98]
|
|
27
|
+
amsterdam.name.should == 'Het Amsterdammertje'
|
|
28
|
+
|
|
21
29
|
Each pub has a name, a latitude and a longitude. More will come later.
|
|
22
30
|
|
|
23
31
|
|
|
24
32
|
limitations
|
|
25
33
|
===========
|
|
26
34
|
|
|
27
|
-
The gem is backed up with pubs in Sweden from the list maintained by Svenska Ölfrämjandet. If you feel you need this for your own country go ahead and contribute.
|
|
35
|
+
The gem is backed up with pubs in Sweden from the list maintained by Svenska Ölfrämjandet. This data is released under a creative commons license as detailed below. You can not use this gem commercially without a specific deal with Svenska Ölfrämjandet. If you feel you need this for your own country go ahead and contribute.
|
|
28
36
|
|
|
37
|
+
<div xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/" about="http://www.svenskaolframjandet.se/pubs_for_gps"><span property="dct:title">Svenska Ölfrämjandets pubdatabas</span> (<a rel="cc:attributionURL" property="cc:attributionName" href="http://www.svenskaolframjandet.se">Svenska Ölfrämjandet</a>) / <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/2.5/se/">CC BY-NC-SA 2.5</a></div>
|
|
29
38
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.2
|
|
@@ -12,25 +12,46 @@ class Pub
|
|
|
12
12
|
[latitude, longitude]
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def Pub::find
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
def Pub::find options = {}
|
|
16
|
+
if options[:address]
|
|
17
|
+
location = Pub::location_from_address options[:address]
|
|
18
|
+
elsif options[:point]
|
|
19
|
+
location = options[:point]
|
|
20
|
+
else
|
|
21
|
+
location = Pub::location_from_current_ip
|
|
22
|
+
end
|
|
23
|
+
sorted_pubs = Pub::find_near location
|
|
24
|
+
count = options[:count] || 1
|
|
25
|
+
count == 1 ? sorted_pubs.first : sorted_pubs[0...count]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def Pub::find_near location
|
|
29
|
+
Pub::all.sort do |one, other|
|
|
30
|
+
distance_to_one = distance_between location, one.location
|
|
31
|
+
distance_to_other = distance_between location, other.location
|
|
25
32
|
distance_to_one <=> distance_to_other
|
|
26
33
|
end
|
|
27
|
-
sorted_pubs.first
|
|
28
34
|
end
|
|
29
35
|
|
|
30
36
|
def Pub::all
|
|
31
37
|
Pub::get_me_them_pubs
|
|
32
38
|
end
|
|
33
39
|
|
|
40
|
+
def Pub::location_from_current_ip
|
|
41
|
+
agent = Mechanize.new
|
|
42
|
+
page = agent.get 'http://freegeoip.net/json/'
|
|
43
|
+
location = JSON.parse page.body
|
|
44
|
+
[location['latitude'], location['longitude']]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def Pub::location_from_address address
|
|
48
|
+
point = Geocoder.search( address ).first.data['geometry']['location']
|
|
49
|
+
[point['lat'], point['lng']]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
:private
|
|
53
|
+
|
|
54
|
+
|
|
34
55
|
def Pub::get_me_them_pubs
|
|
35
56
|
unless defined? @@pubs
|
|
36
57
|
@@pubs = load_pub_list
|
|
@@ -28,4 +28,19 @@ describe Pub do
|
|
|
28
28
|
nearest_pub.latitude .should_not be_nil
|
|
29
29
|
nearest_pub.longitude.should_not be_nil
|
|
30
30
|
end
|
|
31
|
+
|
|
32
|
+
it "should find oliver twist" do
|
|
33
|
+
oliver = Pub.find :address => "Repslagargatan 6, Stockholm"
|
|
34
|
+
oliver.name.should == 'Oliver Twist'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should find relative a point" do
|
|
38
|
+
amsterdam = Pub.find :point => [57.71, 11.98]
|
|
39
|
+
amsterdam.name.should == 'Het Amsterdammertje'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "should find any number of pubs" do
|
|
43
|
+
pubs = Pub.find :count => 5
|
|
44
|
+
pubs.size.should == 5
|
|
45
|
+
end
|
|
31
46
|
end
|
data/thirst.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = "thirst"
|
|
8
|
-
s.version = "0.0.
|
|
8
|
+
s.version = "0.0.2"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Fredrik Rubensson"]
|
|
12
|
-
s.date = "2012-
|
|
12
|
+
s.date = "2012-09-10"
|
|
13
13
|
s.description = "Pub.find if user.in_sweden?"
|
|
14
14
|
s.email = "fredrik@eldfluga.se"
|
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: thirst
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,11 +9,11 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-
|
|
12
|
+
date: 2012-09-10 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: mechanize
|
|
16
|
-
requirement: &
|
|
16
|
+
requirement: &2155716060 !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
19
|
- - ! '>='
|
|
@@ -21,10 +21,10 @@ dependencies:
|
|
|
21
21
|
version: '0'
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
|
-
version_requirements: *
|
|
24
|
+
version_requirements: *2155716060
|
|
25
25
|
- !ruby/object:Gem::Dependency
|
|
26
26
|
name: geocoder
|
|
27
|
-
requirement: &
|
|
27
|
+
requirement: &2155715520 !ruby/object:Gem::Requirement
|
|
28
28
|
none: false
|
|
29
29
|
requirements:
|
|
30
30
|
- - ! '>='
|
|
@@ -32,10 +32,10 @@ dependencies:
|
|
|
32
32
|
version: '0'
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
|
-
version_requirements: *
|
|
35
|
+
version_requirements: *2155715520
|
|
36
36
|
- !ruby/object:Gem::Dependency
|
|
37
37
|
name: rspec
|
|
38
|
-
requirement: &
|
|
38
|
+
requirement: &2155715000 !ruby/object:Gem::Requirement
|
|
39
39
|
none: false
|
|
40
40
|
requirements:
|
|
41
41
|
- - ! '>='
|
|
@@ -43,10 +43,10 @@ dependencies:
|
|
|
43
43
|
version: '0'
|
|
44
44
|
type: :development
|
|
45
45
|
prerelease: false
|
|
46
|
-
version_requirements: *
|
|
46
|
+
version_requirements: *2155715000
|
|
47
47
|
- !ruby/object:Gem::Dependency
|
|
48
48
|
name: bundler
|
|
49
|
-
requirement: &
|
|
49
|
+
requirement: &2155714500 !ruby/object:Gem::Requirement
|
|
50
50
|
none: false
|
|
51
51
|
requirements:
|
|
52
52
|
- - ! '>='
|
|
@@ -54,10 +54,10 @@ dependencies:
|
|
|
54
54
|
version: '0'
|
|
55
55
|
type: :development
|
|
56
56
|
prerelease: false
|
|
57
|
-
version_requirements: *
|
|
57
|
+
version_requirements: *2155714500
|
|
58
58
|
- !ruby/object:Gem::Dependency
|
|
59
59
|
name: jeweler
|
|
60
|
-
requirement: &
|
|
60
|
+
requirement: &2155714000 !ruby/object:Gem::Requirement
|
|
61
61
|
none: false
|
|
62
62
|
requirements:
|
|
63
63
|
- - ! '>='
|
|
@@ -65,10 +65,10 @@ dependencies:
|
|
|
65
65
|
version: '0'
|
|
66
66
|
type: :development
|
|
67
67
|
prerelease: false
|
|
68
|
-
version_requirements: *
|
|
68
|
+
version_requirements: *2155714000
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: guard-rspec
|
|
71
|
-
requirement: &
|
|
71
|
+
requirement: &2155713480 !ruby/object:Gem::Requirement
|
|
72
72
|
none: false
|
|
73
73
|
requirements:
|
|
74
74
|
- - ! '>='
|
|
@@ -76,7 +76,7 @@ dependencies:
|
|
|
76
76
|
version: '0'
|
|
77
77
|
type: :development
|
|
78
78
|
prerelease: false
|
|
79
|
-
version_requirements: *
|
|
79
|
+
version_requirements: *2155713480
|
|
80
80
|
description: Pub.find if user.in_sweden?
|
|
81
81
|
email: fredrik@eldfluga.se
|
|
82
82
|
executables: []
|
|
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
115
115
|
version: '0'
|
|
116
116
|
segments:
|
|
117
117
|
- 0
|
|
118
|
-
hash: -
|
|
118
|
+
hash: -144350713092483912
|
|
119
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
none: false
|
|
121
121
|
requirements:
|