ziptedu 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +79 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/data/zips.csv +42523 -0
- data/lib/ziptedu.rb +39 -0
- data/lib/ziptedu/version.rb +3 -0
- data/lib/ziptedu/zipcode.rb +20 -0
- data/lib/ziptedu/zipcode_parser.rb +36 -0
- data/ziptedu.gemspec +28 -0
- metadata +103 -0
data/lib/ziptedu.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "ziptedu/version"
|
2
|
+
require "ziptedu/zipcode"
|
3
|
+
require "ziptedu/zipcode_parser"
|
4
|
+
|
5
|
+
module Ziptedu
|
6
|
+
class << self
|
7
|
+
|
8
|
+
ZIPS_CSV_FILE = File.join(__dir__, 'data', 'zips.csv')
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
zipcodes
|
12
|
+
end
|
13
|
+
|
14
|
+
def random(how_many = 1)
|
15
|
+
zipcodes.sample(how_many)
|
16
|
+
end
|
17
|
+
|
18
|
+
def zipcode(zipcode)
|
19
|
+
zipcodes.find { |zip| zip.zipcode == zipcode.to_s }
|
20
|
+
end
|
21
|
+
|
22
|
+
def citystate(city, state)
|
23
|
+
zipcodes.find { |zip| zip.city.upcase == city.upcase && zip.state.upcase == state.upcase }
|
24
|
+
end
|
25
|
+
|
26
|
+
def latlong(latitude, longitude)
|
27
|
+
zipcodes.reject { |zip| !zip.longitude || !zip.latitude }
|
28
|
+
.find { |zip| zip.latitude.upcase == latitude.to_s.upcase && zip.longitude.upcase == longitude.to_s.upcase }
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def zipcodes
|
34
|
+
# Cache zipcodes after doing this once...
|
35
|
+
@zipcodes ||= ZipcodeParser.parse ZIPS_CSV_FILE
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Ziptedu
|
4
|
+
class Zipcode
|
5
|
+
attr_accessor :zipcode, :city, :state, :latitude, :longitude
|
6
|
+
attr_reader :type
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
yield self if block_given?
|
10
|
+
end
|
11
|
+
|
12
|
+
def type=(type)
|
13
|
+
@type = type.downcase
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
JSON.pretty_generate({ zipcode: zipcode, type: type, city: city, state: state, latitude: latitude, longitude: longitude })
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module Ziptedu
|
4
|
+
class ZipcodeParser
|
5
|
+
|
6
|
+
def self.parse(csv_file_path)
|
7
|
+
# Initialize to an empty array
|
8
|
+
zipcodes = []
|
9
|
+
|
10
|
+
# We only care about a subset of columns in the CSV file
|
11
|
+
# Map the attributes in the Zipcode class to headers in CSV file
|
12
|
+
attr_to_csv_mapping = {
|
13
|
+
zipcode: "Zipcode",
|
14
|
+
type: "ZipCodeType",
|
15
|
+
city: "City",
|
16
|
+
state: "State",
|
17
|
+
latitude: "Lat",
|
18
|
+
longitude: "Long"
|
19
|
+
}
|
20
|
+
|
21
|
+
CSV.foreach(csv_file_path, headers: true) do |data|
|
22
|
+
|
23
|
+
zipcode = Zipcode.new do |zip|
|
24
|
+
attr_to_csv_mapping.each do |attr, csv_header_name|
|
25
|
+
zip.send "#{attr}=", data[csv_header_name]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
zipcodes << zipcode
|
30
|
+
end
|
31
|
+
|
32
|
+
zipcodes
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/ziptedu.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ziptedu/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ziptedu"
|
8
|
+
spec.version = Ziptedu::VERSION
|
9
|
+
spec.authors = ["Kalman Hazins"]
|
10
|
+
spec.email = ["kalman.hazins@ghs.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{ Zip code to city, state translator. (Ruby) }
|
13
|
+
spec.description = %q{ Functions for looking up zipcode, city, state, latitude and longitude using a zipcode,
|
14
|
+
city + state, or latitude + longitude. You can also get random sets of this data.}
|
15
|
+
spec.homepage = "https://github.com/kalmanh/ziptedu"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ziptedu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kalman Hazins
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: |2-
|
56
|
+
Functions for looking up zipcode, city, state, latitude and longitude using a zipcode,
|
57
|
+
city + state, or latitude + longitude. You can also get random sets of this data.
|
58
|
+
email:
|
59
|
+
- kalman.hazins@ghs.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- lib/data/zips.csv
|
74
|
+
- lib/ziptedu.rb
|
75
|
+
- lib/ziptedu/version.rb
|
76
|
+
- lib/ziptedu/zipcode.rb
|
77
|
+
- lib/ziptedu/zipcode_parser.rb
|
78
|
+
- ziptedu.gemspec
|
79
|
+
homepage: https://github.com/kalmanh/ziptedu
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.4.6
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Zip code to city, state translator. (Ruby)
|
103
|
+
test_files: []
|