zipcodr 0.0.2
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.
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/README.markdown +21 -0
- data/Rakefile +9 -0
- data/lib/zipcodr.rb +3 -0
- data/lib/zipcodr/db.rb +29 -0
- data/lib/zipcodr/version.rb +3 -0
- data/lib/zipcodr/zip_code.rb +18 -0
- data/lib/zipcodr/zipcodr.db +0 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/zipcodr_spec.rb +33 -0
- data/zipcodr.gemspec +24 -0
- metadata +91 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour -f d
|
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Zipcodr
|
2
|
+
=======
|
3
|
+
A library for looking up zip codes and their associated info based on mlightner's [zip codes](https://github.com/mlightner/zip_codes) library with some improvements/bug fixes.
|
4
|
+
|
5
|
+
Install
|
6
|
+
-------
|
7
|
+
`gem install zipcodr`
|
8
|
+
|
9
|
+
---
|
10
|
+
|
11
|
+
Usage
|
12
|
+
-----
|
13
|
+
`require 'zipcodr'`
|
14
|
+
`Zipcodr::find('94720') # returns a ZipCode object.`
|
15
|
+
`Zipcodr::find('94720').zip # returns a zip code string.`
|
16
|
+
`Zipcodr::find('94720').city # returns a city string.`
|
17
|
+
`Zipcodr::find('94720').state # returns a state short code string.`
|
18
|
+
`Zipcodr::find('94720').county # returns a county string.`
|
19
|
+
`Zipcodr::find('94720').long # returns a longitude integer.`
|
20
|
+
`Zipcodr::find('94720').lat # returns a latitude integer.`
|
21
|
+
`Zipcodr::find('94720').valid? # returns a validity boolean.`
|
data/Rakefile
ADDED
data/lib/zipcodr.rb
ADDED
data/lib/zipcodr/db.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Zipcodr
|
2
|
+
|
3
|
+
def self.find(zip)
|
4
|
+
ZipCode.new self.query(zip)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.query(zip)
|
8
|
+
row = Zipcodr::db.execute("select * from zip_codes where zip = '#{zip.to_s}';").first
|
9
|
+
return nil unless (row.kind_of?(Array) && row[1].to_s == zip.to_s)
|
10
|
+
row
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.db
|
14
|
+
db = self.open_db
|
15
|
+
raise "Sorry, Invalid database." unless db.kind_of?(SQLite3::Database)
|
16
|
+
db
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.open_db
|
20
|
+
db = File.dirname(__FILE__) + '/zipcodr.db'
|
21
|
+
raise "Database is not present." unless File.exist?(db)
|
22
|
+
SQLite3::Database.open(db)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.columns
|
26
|
+
['id', 'zip', 'zip_class', 'city', 'county', 'state', 'lat', 'long']
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Zipcodr
|
2
|
+
|
3
|
+
class ZipCode
|
4
|
+
Zipcodr::columns.each {|field| attr_accessor field.to_sym }
|
5
|
+
|
6
|
+
def initialize(row)
|
7
|
+
return nil if row.nil?
|
8
|
+
Zipcodr::columns.each_with_index do |field, index|
|
9
|
+
self.instance_variable_set("@#{field.to_s}".to_sym, row[index])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def valid?
|
14
|
+
!zip.nil?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Zipcodr do
|
4
|
+
context "When I inquire about a zipcode" do
|
5
|
+
it "it returns valid US zip code" do
|
6
|
+
Zipcodr::find('94720').zip.should == '94720'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "it returns valid city" do
|
10
|
+
Zipcodr::find('94720').city.should == 'BERKELEY'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "it returns valid state" do
|
14
|
+
Zipcodr::find('94720').state.should == 'CA'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "it returns valid county" do
|
18
|
+
Zipcodr::find('94720').county.should == 'ALAMEDA'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "it returns valid longitude" do
|
22
|
+
Zipcodr::find('94720').long.should == -122.253582
|
23
|
+
end
|
24
|
+
|
25
|
+
it "it returns valid latitude" do
|
26
|
+
Zipcodr::find('94720').lat.should == 37.866825
|
27
|
+
end
|
28
|
+
|
29
|
+
it "it should be valid zip code object" do
|
30
|
+
Zipcodr::find('94720').should be_valid
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/zipcodr.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "zipcodr/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "zipcodr"
|
7
|
+
s.version = Zipcodr::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Wael Al-Sallami"]
|
10
|
+
s.email = ["wael.alsallami@gmail.com"]
|
11
|
+
s.homepage = "http://wa3l.heroku.com"
|
12
|
+
s.summary = %q{A library for looking up zip codes and their associated info.}
|
13
|
+
s.description = %q{A library for looking up zip codes and their associated info.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "zipcodr"
|
16
|
+
|
17
|
+
s.add_dependency('sqlite3-ruby')
|
18
|
+
s.add_development_dependency('rspec', '2.2.0')
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zipcodr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.2
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Wael Al-Sallami
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-16 00:00:00 +03:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: sqlite3-ruby
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - "="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 2.2.0
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
description: A library for looking up zip codes and their associated info.
|
39
|
+
email:
|
40
|
+
- wael.alsallami@gmail.com
|
41
|
+
executables: []
|
42
|
+
|
43
|
+
extensions: []
|
44
|
+
|
45
|
+
extra_rdoc_files: []
|
46
|
+
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .rspec
|
50
|
+
- Gemfile
|
51
|
+
- README.markdown
|
52
|
+
- Rakefile
|
53
|
+
- lib/zipcodr.rb
|
54
|
+
- lib/zipcodr/db.rb
|
55
|
+
- lib/zipcodr/version.rb
|
56
|
+
- lib/zipcodr/zip_code.rb
|
57
|
+
- lib/zipcodr/zipcodr.db
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
- spec/zipcodr_spec.rb
|
60
|
+
- zipcodr.gemspec
|
61
|
+
has_rdoc: true
|
62
|
+
homepage: http://wa3l.heroku.com
|
63
|
+
licenses: []
|
64
|
+
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: "0"
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project: zipcodr
|
85
|
+
rubygems_version: 1.6.2
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: A library for looking up zip codes and their associated info.
|
89
|
+
test_files:
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
- spec/zipcodr_spec.rb
|