simple_geolocation 0.0.7 → 0.0.8

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.
@@ -14,19 +14,14 @@ module SimpleGeolocation
14
14
  @raw_location = raw_location
15
15
  end
16
16
 
17
- def ip?
18
- !!/^(\d+\.){3}\d+$/.match(@raw_location)
19
- end
20
-
21
17
  # Only brazilian zipcode is supported.
22
18
  def zip?
23
- return false if ip?
24
19
  number = @raw_location.to_s.gsub(/(\.|\D|\-|\s)/, '')
25
20
  number.size == 8
26
21
  end
27
22
 
28
23
  def address?
29
- !ip? && !zip?
24
+ !zip?
30
25
  end
31
26
 
32
27
  def geocode!
@@ -14,9 +14,7 @@ module SimpleGeolocation
14
14
  end
15
15
 
16
16
  def self.instantiate_geoworker_based_on(geocoder)
17
- if geocoder.ip?
18
- GeoIP.new(geocoder)
19
- elsif geocoder.zip?
17
+ if geocoder.zip?
20
18
  Geozip.new(geocoder)
21
19
  else
22
20
  Geokit.new(geocoder)
@@ -1,7 +1,6 @@
1
1
  module SimpleGeolocation
2
2
  module Geoworkers
3
3
  autoload :Base, 'simple_geolocation/geoworkers/base'
4
- autoload :GeoIP, 'simple_geolocation/geoworkers/geoip/geoip'
5
4
  autoload :Geokit, 'simple_geolocation/geoworkers/geokit/geokit'
6
5
  autoload :Geozip, 'simple_geolocation/geoworkers/geozip/geozip'
7
6
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleGeolocation
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
18
18
 
19
19
  s.add_development_dependency "rspec"
20
20
  s.add_dependency "geokit"
21
- s.add_dependency "geoip"
22
21
  s.add_dependency "activesupport"
23
22
  s.add_dependency "brcep"
24
23
 
@@ -3,48 +3,25 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'simple_geolocation')
3
3
 
4
4
  describe SimpleGeolocation do
5
5
 
6
-
7
- it 'should identify if the given location is an ip' do
8
- @geo = SimpleGeolocation::Geocoder.new("189.58.112.247")
9
- @geo.ip?.should be_true
10
- @geo.zip?.should be_false
11
- @geo.address?.should be_false
12
- end
13
-
14
6
  it 'should identify if the given location is a zip' do
15
7
  @geo = SimpleGeolocation::Geocoder.new("89237-440")
16
- @geo.ip?.should be_false
17
8
  @geo.zip?.should be_true
18
9
  @geo.address?.should be_false
19
10
  end
20
11
 
21
12
  it 'should identify if the given location is an address' do
22
13
  @geo = SimpleGeolocation::Geocoder.new("Joinville - SC")
23
- @geo.ip?.should be_false
24
14
  @geo.address?.should be_true
25
15
  @geo.zip?.should be_false
26
16
  end
27
17
 
28
- it "should return the location of an user's based on IP" do
29
- @geo = SimpleGeolocation::Geocoder.new("189.58.112.247")
30
- @geo.ip?.should be_true
31
- @geo.geocode!
32
- @geo.success?.should be_true
33
- @geo.lat.should == -26.3001576
34
- @geo.lng.should == -48.8320838
35
- @geo.city.should == "Joinville"
36
- @geo.state.should == "SC"
37
- @geo.country.should == "Brasil"
38
- @geo.completeness.should == 90
39
- end
40
-
41
18
  it "should return the location of an ordinary address" do
42
19
  @geo = SimpleGeolocation::Geocoder.new("Rua do Principe, 199, Joinville, SC")
43
20
  @geo.address?.should be_true
44
21
  @geo.geocode!
45
22
  @geo.success?.should be_true
46
- @geo.lat.should == -26.30101
47
- @geo.lng.should == -48.8452974
23
+ @geo.lat.should == -26.3009192
24
+ @geo.lng.should == -48.8452937
48
25
  @geo.completeness.should == 90
49
26
  end
50
27
 
@@ -53,9 +30,9 @@ describe SimpleGeolocation do
53
30
  @geo.zip?.should be_true
54
31
  @geo.geocode!
55
32
  @geo.success?.should be_true
56
- @geo.street.should == "Av. Das Américas"
33
+ @geo.street.should == "Avenida das Américas"
57
34
  @geo.district.should == "Barra da Tijuca"
58
- @geo.state.should == "RJ"
35
+ @geo.state.should == "Rio de Janeiro"
59
36
  @geo.city.should == "Rio De Janeiro"
60
37
  @geo.zip.should == "22640-100"
61
38
  @geo.lat.should == -23.0032808
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_geolocation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
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-03-02 00:00:00.000000000Z
12
+ date: 2013-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70243604251040 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70243604251040
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: geokit
27
- requirement: &70243604250540 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,21 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70243604250540
36
- - !ruby/object:Gem::Dependency
37
- name: geoip
38
- requirement: &70243604249780 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
39
41
  none: false
40
42
  requirements:
41
43
  - - ! '>='
42
44
  - !ruby/object:Gem::Version
43
45
  version: '0'
44
- type: :runtime
45
- prerelease: false
46
- version_requirements: *70243604249780
47
46
  - !ruby/object:Gem::Dependency
48
47
  name: activesupport
49
- requirement: &70243604248920 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
50
49
  none: false
51
50
  requirements:
52
51
  - - ! '>='
@@ -54,10 +53,15 @@ dependencies:
54
53
  version: '0'
55
54
  type: :runtime
56
55
  prerelease: false
57
- version_requirements: *70243604248920
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
58
62
  - !ruby/object:Gem::Dependency
59
63
  name: brcep
60
- requirement: &70243604248420 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
61
65
  none: false
62
66
  requirements:
63
67
  - - ! '>='
@@ -65,7 +69,12 @@ dependencies:
65
69
  version: '0'
66
70
  type: :runtime
67
71
  prerelease: false
68
- version_requirements: *70243604248420
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
69
78
  description: ! "\n This gem is used with geolocation in mind, meaning that the
70
79
  main goal is to get a latitude and longitude, but it will return additional data
71
80
  if\n available. With this gem you can pass an IP number or an ZIP number or an
@@ -84,8 +93,6 @@ files:
84
93
  - lib/simple_geolocation.rb
85
94
  - lib/simple_geolocation/geocoder.rb
86
95
  - lib/simple_geolocation/geoworkers/base.rb
87
- - lib/simple_geolocation/geoworkers/geoip/data/GeoLiteCity.dat
88
- - lib/simple_geolocation/geoworkers/geoip/geoip.rb
89
96
  - lib/simple_geolocation/geoworkers/geokit/geokit.rb
90
97
  - lib/simple_geolocation/geoworkers/geoworkers.rb
91
98
  - lib/simple_geolocation/geoworkers/geozip/geozip.rb
@@ -108,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
115
  version: '0'
109
116
  segments:
110
117
  - 0
111
- hash: -4192126495364420408
118
+ hash: 3332890912338725372
112
119
  required_rubygems_version: !ruby/object:Gem::Requirement
113
120
  none: false
114
121
  requirements:
@@ -117,10 +124,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
124
  version: '0'
118
125
  segments:
119
126
  - 0
120
- hash: -4192126495364420408
127
+ hash: 3332890912338725372
121
128
  requirements: []
122
129
  rubyforge_project: simple_geolocation
123
- rubygems_version: 1.8.11
130
+ rubygems_version: 1.8.24
124
131
  signing_key:
125
132
  specification_version: 3
126
133
  summary: A gem that fetch locations based on IP, ZIP and ordinary address through
@@ -1,32 +0,0 @@
1
- require 'geoip'
2
- module SimpleGeolocation
3
- module Geoworkers
4
- class GeoIP < Base
5
-
6
- def process!
7
- get_location!
8
- geocoder.success! if success?
9
- end
10
-
11
- private
12
-
13
- def ip_geocoder
14
- @ip_geocoder ||= ::GeoIP.new(File.join(File.dirname(__FILE__), 'data', 'GeoLiteCity.dat'))
15
- end
16
-
17
- def get_location!
18
- result = ip_geocoder.city(geocoder.raw_location)
19
- if @success = result && result.latitude.present? && result.longitude.present?
20
- new_raw_location = "#{result.latitude}, #{result.longitude}"
21
- geokit = Geokit.new(Geocoder.new(new_raw_location))
22
- geokit.process!
23
- @success = geokit.success?
24
- @location = geokit.location
25
- else
26
- Geokit.new(geocoder).process!
27
- end
28
- end
29
-
30
- end
31
- end
32
- end