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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour -f d
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in zipcodr.gemspec
4
+ gemspec
@@ -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.`
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ desc "Run all specs"
5
+ task :spec do
6
+ Dir["spec/**/*_spec.rb"].each do |spec_path|
7
+ system "rspec #{spec_path}"
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ require "sqlite3"
2
+ require "zipcodr/db"
3
+ require "zipcodr/zip_code"
@@ -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,3 @@
1
+ module Zipcodr
2
+ VERSION = "0.0.2"
3
+ 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
@@ -0,0 +1,3 @@
1
+ Dir[File.expand_path("../../lib/*.rb", __FILE__)].each do |f|
2
+ require f
3
+ end
@@ -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
@@ -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