geolookup 0.5.10 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.rdoc +9 -0
- data/README.md +10 -0
- data/geolookup.gemspec +2 -2
- data/lib/data/AREA_CODE_META_INFO.yml +4801 -0
- data/lib/data/METRO_CODE_TO_NAME.yml +281 -0
- data/lib/data/ZIP_LAT_LONG.yml +124225 -0
- data/lib/geolookup.rb +7 -4
- data/lib/geolookup/usa/areacodes.rb +16 -0
- data/lib/geolookup/usa/metro.rb +37 -0
- data/lib/geolookup/usa/state.rb +13 -4
- data/lib/geolookup/usa/zipcodes.rb +17 -0
- data/lib/geolookup/version.rb +1 -1
- data/spec/lib/areacodes_spec.rb +17 -0
- data/spec/lib/state_spec.rb +8 -0
- data/spec/lib/zipcodes_spec.rb +21 -0
- metadata +15 -3
data/lib/geolookup.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'geolookup/version'
|
2
|
+
require 'geolookup/usa/county'
|
3
|
+
require 'geolookup/usa/state'
|
4
|
+
require 'geolookup/usa/metro'
|
5
|
+
require 'geolookup/country'
|
6
|
+
require 'geolookup/usa/areacodes'
|
7
|
+
require 'geolookup/usa/zipcodes'
|
5
8
|
|
6
9
|
module Geolookup
|
7
10
|
###################################################################
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Geolookup
|
2
|
+
module USA
|
3
|
+
module AreaCodes
|
4
|
+
|
5
|
+
AREA_CODE_META_INFO_FILE = 'AREA_CODE_META_INFO.yml'
|
6
|
+
|
7
|
+
def self.to_h
|
8
|
+
@area_codes_hash ||= Geolookup.load_hash_from_file(AREA_CODE_META_INFO_FILE)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.find(area_code)
|
12
|
+
to_h[area_code.to_s] || {}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Geolookup
|
3
|
+
module USA
|
4
|
+
module Metro
|
5
|
+
METRO_CODE_TO_NAME_FILE = 'METRO_CODE_TO_NAME.yml'
|
6
|
+
|
7
|
+
@metro_code_to_name
|
8
|
+
|
9
|
+
###################################################################
|
10
|
+
# self.code_to_name
|
11
|
+
#
|
12
|
+
# Given a metro code output the metro name
|
13
|
+
# Else return nil
|
14
|
+
#
|
15
|
+
# EX: code_to_name(4) => "Abilene"
|
16
|
+
def self.code_to_name(metro_code)
|
17
|
+
@metro_code_to_name ||= Geolookup.load_hash_from_file(METRO_CODE_TO_NAME_FILE)
|
18
|
+
get_value_from_hash(@metro_code_to_name, metro_code.to_s.to_i)
|
19
|
+
end
|
20
|
+
|
21
|
+
###################################################################
|
22
|
+
# self.get_value_from_hash
|
23
|
+
#
|
24
|
+
# Helper function to reduce code repetition
|
25
|
+
# Given a hash and 1 key returns the value at that hash
|
26
|
+
# Return nil if the either key is not in the hash
|
27
|
+
#
|
28
|
+
# EX: get_value(@metro_code_to_name, 4) => "Abilene"
|
29
|
+
def self.get_value_from_hash(hash, key1)
|
30
|
+
return nil unless hash[key1]
|
31
|
+
hash[key1]
|
32
|
+
end
|
33
|
+
|
34
|
+
private_class_method :get_value_from_hash
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/geolookup/usa/state.rb
CHANGED
@@ -118,23 +118,32 @@ module Geolookup
|
|
118
118
|
end
|
119
119
|
|
120
120
|
###################################################################
|
121
|
-
# self.
|
121
|
+
# self.codes_and_names
|
122
122
|
#
|
123
|
-
# Returns
|
123
|
+
# Returns a hash of state_codes and names
|
124
124
|
#
|
125
125
|
def self.codes_and_names
|
126
126
|
@codes_and_names ||= Geolookup.load_hash_from_file(STATE_CODE_TO_FULL_FILE)
|
127
127
|
end
|
128
128
|
|
129
129
|
###################################################################
|
130
|
-
# self.
|
130
|
+
# self.codes_and_abbreviations
|
131
131
|
#
|
132
|
-
# Returns
|
132
|
+
# Returns a hash of state_codes and abbreviations
|
133
133
|
#
|
134
134
|
def self.codes_and_abbreviations
|
135
135
|
@codes_and_abbreviations ||= Geolookup.load_hash_from_file(STATE_CODE_TO_ABBREVIATION_FILE)
|
136
136
|
end
|
137
137
|
|
138
|
+
###################################################################
|
139
|
+
# self.abbreviations_and_names
|
140
|
+
#
|
141
|
+
# Returns a hash of abbreviations and state names
|
142
|
+
#
|
143
|
+
def self.abbreviations_and_names
|
144
|
+
@state_abbreviation_to_name ||= Geolookup.load_hash_from_file(STATE_ABBREVIATION_TO_NAME_FILE)
|
145
|
+
end
|
146
|
+
|
138
147
|
###################################################################
|
139
148
|
# self.names
|
140
149
|
#
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Geolookup
|
2
|
+
module USA
|
3
|
+
module Zipcodes
|
4
|
+
# In the future if zip information is updated in mysql, the yml can be recreated via the following
|
5
|
+
# zip_lat_long_data = {}
|
6
|
+
# ZipCityGeolocationMapping.find_each {|zip| zip_lat_long_data[zip.zip] = {lat_int: zip.lat_int, long_int: zip.long_int}}
|
7
|
+
# File.open('ZIP_LAT_LONG.yml', "w") {|file| file.puts zip_lat_long_data.to_yaml}
|
8
|
+
|
9
|
+
ZIP_LAT_LONG_FILE = 'ZIP_LAT_LONG.yml'
|
10
|
+
|
11
|
+
def self.lat_long(zipcode)
|
12
|
+
@zip_lat_long_hash ||= Geolookup.load_hash_from_file(ZIP_LAT_LONG_FILE)
|
13
|
+
@zip_lat_long_hash[zipcode.to_i] || {}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/geolookup/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
describe 'Geolookup::USA::AreaCodes' do
|
2
|
+
|
3
|
+
|
4
|
+
describe 'info' do
|
5
|
+
it 'should return data from the Area Code hash if area code is passed in as a string' do
|
6
|
+
expect(Geolookup::USA::AreaCodes.find('202')).to eql({country: 'US', description: '', service: 'y', state: 'DC', type: 'general purpose code'})
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should return data from the Area Code hash if area code is passed in as a number' do
|
10
|
+
expect(Geolookup::USA::AreaCodes.find(202)).to eql({country: 'US', description: '', service: 'y', state: 'DC', type: 'general purpose code'})
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should return an empty hash if there is no area_code data' do
|
14
|
+
expect(Geolookup::USA::AreaCodes.find(2023)).to eql({})
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/lib/state_spec.rb
CHANGED
@@ -96,6 +96,14 @@ describe "Geolookup::USA::State" do
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
+
describe "#abbreviations_and_names" do
|
100
|
+
it "should return a Hash where the key is the abbreviation and the value is the state name" do
|
101
|
+
abbreviations_and_names = Geolookup::USA::State.abbreviations_and_names
|
102
|
+
expect(abbreviations_and_names).to be_kind_of(Hash)
|
103
|
+
expect(abbreviations_and_names['AL']).to be_eql('Alabama')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
99
107
|
describe "#name_to_lat_long" do
|
100
108
|
it "should return a lat / long for state name" do
|
101
109
|
expect(Geolookup::USA::State.name_to_lat_long("Alabama")).to eql(state_lat_long)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
describe 'Geolookup::USA::Zipcodes' do
|
2
|
+
|
3
|
+
|
4
|
+
describe 'lat_long' do
|
5
|
+
it 'should lat long for integer zipcode' do
|
6
|
+
expect(Geolookup::USA::Zipcodes.lat_long('90012')).to eql({lat_int: 34067827, long_int: -118242233})
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should lat long for string zipcode' do
|
10
|
+
expect(Geolookup::USA::Zipcodes.lat_long(90012)).to eql({lat_int: 34067827, long_int: -118242233})
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should not care about leading zeros' do
|
14
|
+
expect(Geolookup::USA::Zipcodes.lat_long(501)).to eql(Geolookup::USA::Zipcodes.lat_long('00501'))
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should return an empty hash if there is no zipcode data' do
|
18
|
+
expect(Geolookup::USA::Zipcodes.lat_long('900012')).to eql({})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geolookup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Austin Fonacier
|
8
8
|
- David Butler
|
9
9
|
- Jeffrey Lee
|
10
|
+
- Wei Yan
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date:
|
14
|
+
date: 2016-05-11 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: bundler
|
@@ -59,6 +60,7 @@ email:
|
|
59
60
|
- austin@spokeo.com
|
60
61
|
- dwbutler@ucla.edu
|
61
62
|
- jlee@spokeo.com
|
63
|
+
- wyan@spokeo.com
|
62
64
|
executables: []
|
63
65
|
extensions: []
|
64
66
|
extra_rdoc_files: []
|
@@ -72,6 +74,7 @@ files:
|
|
72
74
|
- README.md
|
73
75
|
- Rakefile
|
74
76
|
- geolookup.gemspec
|
77
|
+
- lib/data/AREA_CODE_META_INFO.yml
|
75
78
|
- lib/data/COUNTRY_CODE_TO_NAME.yml
|
76
79
|
- lib/data/COUNTRY_LAT_LONG.yml
|
77
80
|
- lib/data/COUNTRY_NAME_TO_CODE.yml
|
@@ -79,20 +82,27 @@ files:
|
|
79
82
|
- lib/data/COUNTY_IGNORED_STATES.yml
|
80
83
|
- lib/data/COUNTY_LAT_LONG.yml
|
81
84
|
- lib/data/COUNTY_NAME_TO_CODE.yml
|
85
|
+
- lib/data/METRO_CODE_TO_NAME.yml
|
82
86
|
- lib/data/STATE_CODE_TO_DISPLAY_NAME.yml
|
83
87
|
- lib/data/STATE_CODE_TO_FULL.yml
|
84
88
|
- lib/data/STATE_CODE_TO_STATE.yml
|
85
89
|
- lib/data/STATE_FULL_STATE_NAMES.yml
|
86
90
|
- lib/data/STATE_LAT_LONG.yml
|
87
91
|
- lib/data/STATE_NAME_TO_CODE.yml
|
92
|
+
- lib/data/ZIP_LAT_LONG.yml
|
88
93
|
- lib/geolookup.rb
|
89
94
|
- lib/geolookup/country.rb
|
95
|
+
- lib/geolookup/usa/areacodes.rb
|
90
96
|
- lib/geolookup/usa/county.rb
|
97
|
+
- lib/geolookup/usa/metro.rb
|
91
98
|
- lib/geolookup/usa/state.rb
|
99
|
+
- lib/geolookup/usa/zipcodes.rb
|
92
100
|
- lib/geolookup/version.rb
|
101
|
+
- spec/lib/areacodes_spec.rb
|
93
102
|
- spec/lib/country_spec.rb
|
94
103
|
- spec/lib/county_spec.rb
|
95
104
|
- spec/lib/state_spec.rb
|
105
|
+
- spec/lib/zipcodes_spec.rb
|
96
106
|
- spec/spec_helper.rb
|
97
107
|
homepage: https://github.com/spokeo/geolookup
|
98
108
|
licenses:
|
@@ -114,12 +124,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
124
|
version: '0'
|
115
125
|
requirements: []
|
116
126
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.4.6
|
118
128
|
signing_key:
|
119
129
|
specification_version: 4
|
120
130
|
summary: Common geo lookups
|
121
131
|
test_files:
|
132
|
+
- spec/lib/areacodes_spec.rb
|
122
133
|
- spec/lib/country_spec.rb
|
123
134
|
- spec/lib/county_spec.rb
|
124
135
|
- spec/lib/state_spec.rb
|
136
|
+
- spec/lib/zipcodes_spec.rb
|
125
137
|
- spec/spec_helper.rb
|