thirst 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
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
1
+ 0.0.2
@@ -12,25 +12,46 @@ class Pub
12
12
  [latitude, longitude]
13
13
  end
14
14
 
15
- def Pub::find
16
- agent = Mechanize.new
17
- page = agent.get 'http://freegeoip.net/json/'
18
- my_location = JSON.parse page.body
19
- my_latitude = my_location['latitude']
20
- my_longitude = my_location['longitude']
21
- my_location = [my_latitude,my_longitude]
22
- sorted_pubs = Pub::all.sort do |one, other|
23
- distance_to_one = distance_between my_location, one.location
24
- distance_to_other = distance_between my_location, other.location
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
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "thirst"
8
- s.version = "0.0.1"
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-08-19"
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.1
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-08-19 00:00:00.000000000 Z
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: &2157550900 !ruby/object:Gem::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: *2157550900
24
+ version_requirements: *2155716060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: geocoder
27
- requirement: &2157550420 !ruby/object:Gem::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: *2157550420
35
+ version_requirements: *2155715520
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2157549920 !ruby/object:Gem::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: *2157549920
46
+ version_requirements: *2155715000
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &2157549400 !ruby/object:Gem::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: *2157549400
57
+ version_requirements: *2155714500
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &2157548880 !ruby/object:Gem::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: *2157548880
68
+ version_requirements: *2155714000
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-rspec
71
- requirement: &2157548360 !ruby/object:Gem::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: *2157548360
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: -1786957553276533335
118
+ hash: -144350713092483912
119
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  none: false
121
121
  requirements: