where 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -1
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/{LICENSE → LICENSE.txt} +4 -2
- data/README.md +54 -0
- data/Rakefile +1 -53
- data/lib/where.rb +8 -8
- data/lib/where/address.rb +26 -27
- data/lib/where/base.rb +27 -30
- data/lib/where/ip_address.rb +24 -19
- data/lib/where/version.rb +3 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/where_spec.rb +115 -0
- data/where.gemspec +25 -0
- metadata +105 -62
- data/.document +0 -5
- data/README.rdoc +0 -33
- data/VERSION +0 -1
- data/Where.gemspec +0 -57
- data/test/helper.rb +0 -10
- data/test/test_where.rb +0 -86
data/.gitignore
CHANGED
data/.rspec
ADDED
data/Gemfile
ADDED
data/{LICENSE → LICENSE.txt}
RENAMED
@@ -1,4 +1,6 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2013 Matt Venables
|
2
|
+
|
3
|
+
MIT License
|
2
4
|
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
6
|
a copy of this software and associated documentation files (the
|
@@ -17,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
Where
|
2
|
+
=====
|
3
|
+
|
4
|
+
A basic geolocation library for Ruby.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'where'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install where
|
20
|
+
|
21
|
+
Usage
|
22
|
+
-----
|
23
|
+
|
24
|
+
Search by Address:
|
25
|
+
|
26
|
+
result = Where.is '4 yawkey way boston ma'
|
27
|
+
if result.success?
|
28
|
+
puts "Address: #{result.address}"
|
29
|
+
puts "Street Number: #{result.street_number}"
|
30
|
+
puts "Street: #{result.street}"
|
31
|
+
puts "City: #{result.city}"
|
32
|
+
puts "State: #{result.state}"
|
33
|
+
puts "Zip: #{result.postal_code}"
|
34
|
+
puts "Country: #{result.country}"
|
35
|
+
puts "Lat: #{result.lat}"
|
36
|
+
puts "Lng: #{result.lng}"
|
37
|
+
end
|
38
|
+
|
39
|
+
Or, by IP-Address:
|
40
|
+
|
41
|
+
result = Where.is "173.194.33.104"
|
42
|
+
...
|
43
|
+
|
44
|
+
Testing
|
45
|
+
-------
|
46
|
+
|
47
|
+
Run the spec suite by running:
|
48
|
+
|
49
|
+
rspec
|
50
|
+
|
51
|
+
Copyright
|
52
|
+
---------
|
53
|
+
|
54
|
+
Copyright (c) 2013 Matt Venables. See LICENSE.txt for details.
|
data/Rakefile
CHANGED
@@ -1,53 +1 @@
|
|
1
|
-
require
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "where"
|
8
|
-
gem.summary = %Q{A simple geolocation library.}
|
9
|
-
gem.description = %Q{A very simple geolocation library for searching based on postal address or ip address.}
|
10
|
-
gem.email = "matt@veg.etabl.es"
|
11
|
-
gem.homepage = "http://github.com/vegetables/where"
|
12
|
-
gem.authors = ["Matt Venables"]
|
13
|
-
gem.add_development_dependency "shoulda", ">= 0"
|
14
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
-
end
|
16
|
-
Jeweler::GemcutterTasks.new
|
17
|
-
rescue LoadError
|
18
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
-
end
|
20
|
-
|
21
|
-
require 'rake/testtask'
|
22
|
-
Rake::TestTask.new(:test) do |test|
|
23
|
-
test.libs << 'lib' << 'test'
|
24
|
-
test.pattern = 'test/**/test_*.rb'
|
25
|
-
test.verbose = true
|
26
|
-
end
|
27
|
-
|
28
|
-
begin
|
29
|
-
require 'rcov/rcovtask'
|
30
|
-
Rcov::RcovTask.new do |test|
|
31
|
-
test.libs << 'test'
|
32
|
-
test.pattern = 'test/**/test_*.rb'
|
33
|
-
test.verbose = true
|
34
|
-
end
|
35
|
-
rescue LoadError
|
36
|
-
task :rcov do
|
37
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
task :test => :check_dependencies
|
42
|
-
|
43
|
-
task :default => :test
|
44
|
-
|
45
|
-
require 'rake/rdoctask'
|
46
|
-
Rake::RDocTask.new do |rdoc|
|
47
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
-
|
49
|
-
rdoc.rdoc_dir = 'rdoc'
|
50
|
-
rdoc.title = "where #{version}"
|
51
|
-
rdoc.rdoc_files.include('README*')
|
52
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
-
end
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/where.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
+
require "where/version"
|
1
2
|
require 'where/base'
|
2
3
|
require 'where/address'
|
3
4
|
require 'where/ip_address'
|
4
5
|
|
5
|
-
module Where
|
6
|
-
def self.is(address = "")
|
7
|
-
address
|
8
|
-
|
9
|
-
Where::IpAddress.geocode address
|
6
|
+
module Where
|
7
|
+
def self.is(address = "", opts={})
|
8
|
+
if address.to_s.match(/^(\d{1,3}\.){3}\d{1,3}$/)
|
9
|
+
Where::IpAddress.geocode(address, opts)
|
10
10
|
else
|
11
|
-
Where::Address.geocode
|
12
|
-
end
|
11
|
+
Where::Address.geocode(address, opts)
|
12
|
+
end
|
13
13
|
end
|
14
|
-
end
|
14
|
+
end
|
data/lib/where/address.rb
CHANGED
@@ -1,43 +1,42 @@
|
|
1
1
|
module Where
|
2
|
-
class Address < Where::Base
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
super(address, api_url || GEOCODER_URL)
|
8
|
-
end
|
2
|
+
class Address < Where::Base
|
3
|
+
GEOCODER_URL = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address='
|
4
|
+
|
5
|
+
def self.geocode(address, opts={})
|
6
|
+
super(address, GEOCODER_URL)
|
9
7
|
end
|
10
|
-
|
11
|
-
def results=(results_array
|
12
|
-
results_array.each { |result| self.
|
8
|
+
|
9
|
+
def results=(results_array=[])
|
10
|
+
results_array.each { |result| self.attributes = result }
|
13
11
|
end
|
14
|
-
|
15
|
-
def types=(val
|
12
|
+
|
13
|
+
def types=(val=[])
|
16
14
|
@accuracy = determine_type(val)
|
17
15
|
end
|
18
|
-
|
16
|
+
|
19
17
|
def formatted_address=(val)
|
20
18
|
@address = val
|
21
19
|
end
|
22
|
-
|
23
|
-
def address_components=(components
|
20
|
+
|
21
|
+
def address_components=(components=[])
|
24
22
|
components.each do |component|
|
25
|
-
type = determine_type
|
23
|
+
type = determine_type(component['types'])
|
26
24
|
next if type.empty?
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
|
26
|
+
if %w(region country).include?(type)
|
27
|
+
send("#{type}_code=", component['short_name'])
|
28
|
+
send("#{type}_name=", component['long_name'])
|
30
29
|
else
|
31
|
-
|
30
|
+
send("#{type}=", component['long_name'])
|
32
31
|
end
|
33
32
|
end
|
34
33
|
end
|
35
|
-
|
36
|
-
def geometry=(val
|
37
|
-
self.
|
34
|
+
|
35
|
+
def geometry=(val={})
|
36
|
+
self.attributes = val['location']
|
38
37
|
end
|
39
|
-
|
40
|
-
|
38
|
+
|
39
|
+
private
|
41
40
|
|
42
41
|
def determine_type(val = [])
|
43
42
|
{ 'street_address' => 'street_address',
|
@@ -49,10 +48,10 @@ module Where
|
|
49
48
|
'postal_code' => 'postal_code',
|
50
49
|
'country' => 'country'
|
51
50
|
}.each do |k, v|
|
52
|
-
return v if val.include?
|
51
|
+
return v if val.include?(k)
|
53
52
|
end
|
54
53
|
""
|
55
54
|
end
|
56
|
-
|
55
|
+
|
57
56
|
end
|
58
57
|
end
|
data/lib/where/base.rb
CHANGED
@@ -4,36 +4,32 @@ require 'active_support'
|
|
4
4
|
|
5
5
|
module Where
|
6
6
|
class Base
|
7
|
-
attr_accessor :street_number, :street, :city, :neighborhood, :postal_code,
|
8
|
-
:region_code, :region_name, :accuracy,
|
9
|
-
:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
rescue
|
18
|
-
self.new
|
19
|
-
end
|
20
|
-
end
|
7
|
+
attr_accessor :street_number, :street, :city, :neighborhood, :postal_code,
|
8
|
+
:region_code, :region_name, :accuracy, :country_code,
|
9
|
+
:country_name, :lat, :lng
|
10
|
+
|
11
|
+
def self.geocode(address, api_url='')
|
12
|
+
url = api_url + URI.escape(address)
|
13
|
+
response = Net::HTTP.get_response(URI.parse(url))
|
14
|
+
new(response.body)
|
15
|
+
rescue
|
16
|
+
new
|
21
17
|
end
|
22
|
-
|
23
|
-
def initialize(data
|
24
|
-
|
25
|
-
return if
|
26
|
-
self.
|
18
|
+
|
19
|
+
def initialize(data='')
|
20
|
+
json = ActiveSupport::JSON.decode(data)
|
21
|
+
return if json.nil? || json.empty?
|
22
|
+
self.attributes = json
|
27
23
|
self
|
28
24
|
end
|
29
|
-
|
30
|
-
def
|
25
|
+
|
26
|
+
def attributes=(opts={})
|
31
27
|
opts.each do |k,v|
|
32
28
|
var_name = ActiveSupport::Inflector.underscore(k)
|
33
29
|
if self.respond_to?("#{var_name}=")
|
34
30
|
self.send "#{var_name}=", v
|
35
31
|
else
|
36
|
-
self.instance_variable_set("@#{var_name}", v)
|
32
|
+
self.instance_variable_set("@#{var_name}", v)
|
37
33
|
end
|
38
34
|
end
|
39
35
|
end
|
@@ -42,29 +38,30 @@ module Where
|
|
42
38
|
def success?
|
43
39
|
@status == 'OK' || !@region_code.nil?
|
44
40
|
end
|
45
|
-
|
41
|
+
|
46
42
|
def street_address
|
47
43
|
arr = [street_number, street].compact
|
48
44
|
arr.empty? ? nil : arr.join(" ")
|
49
45
|
end
|
50
46
|
|
51
47
|
def address
|
52
|
-
arr = [street_address, city, region(true), postal_code, country(true)]
|
48
|
+
arr = [street_address, city, region(true), postal_code, country(true)]
|
49
|
+
arr.compact!
|
53
50
|
arr.empty? ? nil : arr.join(", ")
|
54
51
|
end
|
55
|
-
|
56
|
-
def city(use_neighborhood
|
52
|
+
|
53
|
+
def city(use_neighborhood=false)
|
57
54
|
@neighborhood && use_neighborhood ? @neighborhood : @city
|
58
55
|
end
|
59
|
-
|
60
|
-
def country(short_version
|
56
|
+
|
57
|
+
def country(short_version=false)
|
61
58
|
short_version ? @country_code : @country_name
|
62
59
|
end
|
63
60
|
|
64
|
-
def region(short_version
|
61
|
+
def region(short_version=false)
|
65
62
|
short_version ? @region_code : @region_name
|
66
63
|
end
|
67
64
|
|
68
65
|
end
|
69
66
|
|
70
|
-
end
|
67
|
+
end
|
data/lib/where/ip_address.rb
CHANGED
@@ -1,33 +1,38 @@
|
|
1
1
|
module Where
|
2
2
|
class IpAddress < Where::Base
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
GEOPLUGIN_URL = 'http://www.geoplugin.net/json.gp?ip='
|
4
|
+
FREEGEOIP_URL = 'http://freegeoip.net/json/'
|
5
|
+
|
6
|
+
def self.geocode(address, opts={})
|
7
|
+
api_url = opts[:geocoder] == 'geoplugin' ? GEOPLUGIN_URL : FREEGEOIP_URL
|
8
|
+
super(address, api_url)
|
9
9
|
end
|
10
|
-
|
11
|
-
def initialize(
|
12
|
-
data
|
13
|
-
super(data.empty? ? data : data.gsub('geoplugin_', ''))
|
10
|
+
|
11
|
+
def initialize(data='')
|
12
|
+
super(data.to_s.gsub('geoplugin_', ''))
|
14
13
|
end
|
15
|
-
|
14
|
+
|
16
15
|
def latitude=(val)
|
17
16
|
@lat = val
|
18
17
|
end
|
19
|
-
|
18
|
+
|
20
19
|
def longitude=(val)
|
21
20
|
@lng = val
|
22
21
|
end
|
23
|
-
|
22
|
+
|
24
23
|
def accuracy
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
if street
|
25
|
+
'street_address'
|
26
|
+
elsif city
|
27
|
+
'city'
|
28
|
+
elsif region
|
29
|
+
'region'
|
30
|
+
elsif country
|
31
|
+
'country'
|
32
|
+
else
|
33
|
+
''
|
34
|
+
end
|
30
35
|
end
|
31
|
-
|
36
|
+
|
32
37
|
end
|
33
38
|
end
|
data/spec/spec_helper.rb
ADDED
data/spec/where_spec.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Where do
|
4
|
+
describe '.is' do
|
5
|
+
context 'given nil' do
|
6
|
+
it 'returns an empty object' do
|
7
|
+
result = Where.is(nil)
|
8
|
+
result.accuracy.should be_nil
|
9
|
+
result.address.should be_nil
|
10
|
+
result.street_number.should be_nil
|
11
|
+
result.street.should be_nil
|
12
|
+
result.city.should be_nil
|
13
|
+
result.region.should be_nil
|
14
|
+
result.postal_code.should be_nil
|
15
|
+
result.country.should be_nil
|
16
|
+
result.lat.should be_nil
|
17
|
+
result.lng.should be_nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'given an empty string' do
|
22
|
+
it 'returns an empty object' do
|
23
|
+
result = Where.is('')
|
24
|
+
result.accuracy.should be_nil
|
25
|
+
result.address.should be_nil
|
26
|
+
result.street_number.should be_nil
|
27
|
+
result.street.should be_nil
|
28
|
+
result.city.should be_nil
|
29
|
+
result.region.should be_nil
|
30
|
+
result.postal_code.should be_nil
|
31
|
+
result.country.should be_nil
|
32
|
+
result.lat.should be_nil
|
33
|
+
result.lng.should be_nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'given an IP address' do
|
38
|
+
context 'using the default geocoder (freegeoip.net)' do
|
39
|
+
it 'returns a valid geolocation object' do
|
40
|
+
result = Where.is("173.194.33.104")
|
41
|
+
result.accuracy.should == 'city'
|
42
|
+
result.address.should_not be_nil
|
43
|
+
result.street_number.should be_nil
|
44
|
+
result.street.should be_nil
|
45
|
+
result.city.should == 'Mountain View'
|
46
|
+
result.city(true).should == 'Mountain View'
|
47
|
+
result.region.should == 'California'
|
48
|
+
result.region(true).should == 'CA'
|
49
|
+
result.postal_code.should be_nil
|
50
|
+
result.country.should == 'United States'
|
51
|
+
result.country(true).should == 'US'
|
52
|
+
result.lat.should_not be_nil
|
53
|
+
result.lng.should_not be_nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'using geoplugin.net as the geocoder' do
|
58
|
+
it 'returns a valid geolocation object' do
|
59
|
+
result = Where.is("173.194.33.104", geocoder: 'geoplugin')
|
60
|
+
result.accuracy.should == 'city'
|
61
|
+
result.address.should_not be_nil
|
62
|
+
result.street_number.should be_nil
|
63
|
+
result.street.should be_nil
|
64
|
+
result.city.should == 'Mountain View'
|
65
|
+
result.city(true).should == 'Mountain View'
|
66
|
+
result.region.should == 'California'
|
67
|
+
result.region(true).should == 'CA'
|
68
|
+
result.postal_code.should be_nil
|
69
|
+
result.country.should == 'United States'
|
70
|
+
result.country(true).should == 'US'
|
71
|
+
result.lat.should_not be_nil
|
72
|
+
result.lng.should_not be_nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'given a specific physical address' do
|
78
|
+
it 'returns a valid geolocation object' do
|
79
|
+
result = Where.is("4 yawkey way boston ma")
|
80
|
+
result.accuracy.should == 'street_address'
|
81
|
+
result.address.should_not be_nil
|
82
|
+
result.street_number.should == '4'
|
83
|
+
result.street.should == 'Yawkey Way'
|
84
|
+
result.city.should == 'Boston'
|
85
|
+
result.city(true).should == 'West Fens'
|
86
|
+
result.region.should == 'Massachusetts'
|
87
|
+
result.region(true).should == 'MA'
|
88
|
+
result.postal_code.should == '02215'
|
89
|
+
result.country.should == 'United States'
|
90
|
+
result.country(true).should == 'US'
|
91
|
+
result.lat.should_not be_nil
|
92
|
+
result.lng.should_not be_nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'given a neighborhood physical address' do
|
97
|
+
it 'returns a valid geolocation object' do
|
98
|
+
result = Where.is("North End Boston MA")
|
99
|
+
result.accuracy.should == 'neighborhood'
|
100
|
+
result.address.should_not be_nil
|
101
|
+
result.street_number.should be_nil
|
102
|
+
result.street.should be_nil
|
103
|
+
result.city.should == 'Boston'
|
104
|
+
result.city(true).should == 'North End'
|
105
|
+
result.region.should == 'Massachusetts'
|
106
|
+
result.region(true).should == 'MA'
|
107
|
+
result.postal_code.should be_nil
|
108
|
+
result.country.should == 'United States'
|
109
|
+
result.country(true).should == 'US'
|
110
|
+
result.lat.should_not be_nil
|
111
|
+
result.lng.should_not be_nil
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
data/where.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'where/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "where"
|
8
|
+
gem.version = Where::VERSION
|
9
|
+
gem.authors = ["Matt Venables"]
|
10
|
+
gem.email = ["mattvenables@gmail.com"]
|
11
|
+
gem.description = %q{A very simple geolocation library for searching based on postal address or ip address.}
|
12
|
+
gem.summary = %q{A simple geolocation library.}
|
13
|
+
gem.homepage = "http://github.com/venables/where"
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_dependency "activesupport"
|
22
|
+
gem.add_development_dependency "pry"
|
23
|
+
gem.add_development_dependency "rake"
|
24
|
+
gem.add_development_dependency "rspec"
|
25
|
+
end
|
metadata
CHANGED
@@ -1,90 +1,133 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: where
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
version: 0.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.2
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Matt Venables
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
name: shoulda
|
12
|
+
date: 2013-02-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
type: :runtime
|
22
16
|
prerelease: false
|
23
|
-
|
17
|
+
name: activesupport
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
24
|
+
requirement: !ruby/object:Gem::Requirement
|
24
25
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
|
30
|
-
version: "0"
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
31
|
type: :development
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
prerelease: false
|
33
|
+
name: pry
|
34
|
+
version_requirements: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
name: rake
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
name: rspec
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: A very simple geolocation library for searching based on postal address
|
79
|
+
or ip address.
|
80
|
+
email:
|
81
|
+
- mattvenables@gmail.com
|
35
82
|
executables: []
|
36
|
-
|
37
83
|
extensions: []
|
38
|
-
|
39
|
-
|
40
|
-
- LICENSE
|
41
|
-
- README.rdoc
|
42
|
-
files:
|
43
|
-
- .document
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
44
86
|
- .gitignore
|
45
|
-
-
|
46
|
-
-
|
87
|
+
- .rspec
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.md
|
47
91
|
- Rakefile
|
48
|
-
- VERSION
|
49
|
-
- Where.gemspec
|
50
92
|
- lib/where.rb
|
51
93
|
- lib/where/address.rb
|
52
94
|
- lib/where/base.rb
|
53
95
|
- lib/where/ip_address.rb
|
54
|
-
-
|
55
|
-
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
96
|
+
- lib/where/version.rb
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
- spec/where_spec.rb
|
99
|
+
- where.gemspec
|
100
|
+
homepage: http://github.com/venables/where
|
101
|
+
licenses:
|
102
|
+
- MIT
|
60
103
|
post_install_message:
|
61
|
-
rdoc_options:
|
62
|
-
|
63
|
-
require_paths:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
64
106
|
- lib
|
65
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
108
|
none: false
|
67
|
-
requirements:
|
68
|
-
- -
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
segments:
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
segments:
|
71
113
|
- 0
|
72
|
-
|
73
|
-
|
114
|
+
hash: 1629129296734922149
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
117
|
none: false
|
75
|
-
requirements:
|
76
|
-
- -
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
segments:
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
segments:
|
79
122
|
- 0
|
80
|
-
|
123
|
+
hash: 1629129296734922149
|
124
|
+
version: '0'
|
81
125
|
requirements: []
|
82
|
-
|
83
126
|
rubyforge_project:
|
84
|
-
rubygems_version: 1.
|
127
|
+
rubygems_version: 1.8.23
|
85
128
|
signing_key:
|
86
129
|
specification_version: 3
|
87
130
|
summary: A simple geolocation library.
|
88
|
-
test_files:
|
89
|
-
-
|
90
|
-
-
|
131
|
+
test_files:
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
- spec/where_spec.rb
|
data/.document
DELETED
data/README.rdoc
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
= Where
|
2
|
-
|
3
|
-
A basic geolocation library for Ruby.
|
4
|
-
|
5
|
-
== Installation
|
6
|
-
|
7
|
-
gem install 'where'
|
8
|
-
|
9
|
-
== Usage
|
10
|
-
|
11
|
-
Search by Address:
|
12
|
-
|
13
|
-
result = Where.is '4 yawkey way boston ma'
|
14
|
-
if result.success?
|
15
|
-
puts "Address: #{result.address}"
|
16
|
-
puts "Street Number: #{result.street_number}"
|
17
|
-
puts "Street: #{result.street}"
|
18
|
-
puts "City: #{result.city}"
|
19
|
-
puts "State: #{result.state}"
|
20
|
-
puts "Zip: #{result.postal_code}"
|
21
|
-
puts "Country: #{result.country}"
|
22
|
-
puts "Lat: #{result.lat}"
|
23
|
-
puts "Lng: #{result.lng}"
|
24
|
-
end
|
25
|
-
|
26
|
-
Or, by IP-Address:
|
27
|
-
|
28
|
-
result = Where.is "173.194.33.104"
|
29
|
-
...
|
30
|
-
|
31
|
-
== Copyright
|
32
|
-
|
33
|
-
Copyright (c) 2010 Matt Venables. See LICENSE for details.
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.1
|
data/Where.gemspec
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{where}
|
8
|
-
s.version = "0.0.1"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Matt Venables"]
|
12
|
-
s.date = %q{2010-10-03}
|
13
|
-
s.description = %q{A very simple geolocation library for searching based on postal address or ip address.}
|
14
|
-
s.email = %q{matt@veg.etabl.es}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"Where.gemspec",
|
27
|
-
"lib/where.rb",
|
28
|
-
"lib/where/address.rb",
|
29
|
-
"lib/where/base.rb",
|
30
|
-
"lib/where/ip_address.rb",
|
31
|
-
"test/helper.rb",
|
32
|
-
"test/test_where.rb"
|
33
|
-
]
|
34
|
-
s.homepage = %q{http://github.com/vegetables/where}
|
35
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
-
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version = %q{1.3.7}
|
38
|
-
s.summary = %q{A simple geolocation library.}
|
39
|
-
s.test_files = [
|
40
|
-
"test/helper.rb",
|
41
|
-
"test/test_where.rb"
|
42
|
-
]
|
43
|
-
|
44
|
-
if s.respond_to? :specification_version then
|
45
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
-
s.specification_version = 3
|
47
|
-
|
48
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
-
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
50
|
-
else
|
51
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
52
|
-
end
|
53
|
-
else
|
54
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
data/test/helper.rb
DELETED
data/test/test_where.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestWhere < Test::Unit::TestCase
|
4
|
-
|
5
|
-
should "build an empty object when given a nil address" do
|
6
|
-
result = Where.is(nil)
|
7
|
-
assert result.accuracy.nil?
|
8
|
-
assert result.address.nil?
|
9
|
-
assert result.street_number.nil?
|
10
|
-
assert result.street.nil?
|
11
|
-
assert result.city.nil?
|
12
|
-
assert result.region.nil?
|
13
|
-
assert result.postal_code.nil?
|
14
|
-
assert result.country.nil?
|
15
|
-
assert result.lat.nil?
|
16
|
-
assert result.lng.nil?
|
17
|
-
end
|
18
|
-
|
19
|
-
should "build an empty object when given an empty address" do
|
20
|
-
result = Where.is("")
|
21
|
-
assert result.accuracy.nil?
|
22
|
-
assert result.address.nil?
|
23
|
-
assert result.street_number.nil?
|
24
|
-
assert result.street.nil?
|
25
|
-
assert result.city.nil?
|
26
|
-
assert result.region.nil?
|
27
|
-
assert result.postal_code.nil?
|
28
|
-
assert result.country.nil?
|
29
|
-
assert result.lat.nil?
|
30
|
-
assert result.lng.nil?
|
31
|
-
end
|
32
|
-
|
33
|
-
should "build a valid geolocation object when given a street address" do
|
34
|
-
result = Where.is("4 yawkey way boston ma")
|
35
|
-
assert result.accuracy == 'street_address'
|
36
|
-
assert !result.address.nil?
|
37
|
-
assert result.street_number == '4'
|
38
|
-
assert result.street == 'Yawkey Way'
|
39
|
-
assert result.city == 'Boston'
|
40
|
-
assert result.city(true) == 'Boston'
|
41
|
-
assert result.region == 'Massachusetts'
|
42
|
-
assert result.region(true) == 'MA'
|
43
|
-
assert result.postal_code == '02215'
|
44
|
-
assert result.country == 'United States'
|
45
|
-
assert result.country(true) == 'US'
|
46
|
-
assert !result.lat.nil?
|
47
|
-
assert !result.lng.nil?
|
48
|
-
end
|
49
|
-
|
50
|
-
should "build a valid geolocation object when given an address in a neighborhood" do
|
51
|
-
result = Where.is("brighton ma")
|
52
|
-
assert result.accuracy == 'neighborhood'
|
53
|
-
assert !result.address.nil?
|
54
|
-
assert result.street_number.nil?
|
55
|
-
assert result.street.nil?
|
56
|
-
assert result.city == 'Boston'
|
57
|
-
assert result.city(true) == 'Brighton'
|
58
|
-
assert result.region == 'Massachusetts'
|
59
|
-
assert result.region(true) == 'MA'
|
60
|
-
assert result.postal_code.nil?
|
61
|
-
assert result.country == 'United States'
|
62
|
-
assert result.country(true) == 'US'
|
63
|
-
assert !result.lat.nil?
|
64
|
-
assert !result.lng.nil?
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
should "build a valid geolocation object when given an ip address" do
|
69
|
-
result = Where.is("173.194.33.104")
|
70
|
-
assert result.accuracy == 'city'
|
71
|
-
assert !result.address.nil?
|
72
|
-
assert result.street_number.nil?
|
73
|
-
assert result.street.nil?
|
74
|
-
assert result.city == 'Mountain View'
|
75
|
-
assert result.city(true) == 'Mountain View'
|
76
|
-
assert result.region == 'California'
|
77
|
-
assert result.region(true) == 'CA'
|
78
|
-
assert result.postal_code.nil?
|
79
|
-
assert result.country == 'United States'
|
80
|
-
assert result.country(true) == 'US'
|
81
|
-
assert !result.lat.nil?
|
82
|
-
assert !result.lng.nil?
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
end
|