zipster 0.0.1

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 ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in zipster.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ zipster (0.0.1)
5
+ algorithms
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ algorithms (0.3.0)
11
+ diff-lcs (1.1.2)
12
+ rspec (2.1.0)
13
+ rspec-core (~> 2.1.0)
14
+ rspec-expectations (~> 2.1.0)
15
+ rspec-mocks (~> 2.1.0)
16
+ rspec-core (2.1.0)
17
+ rspec-expectations (2.1.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.1.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ algorithms
26
+ rspec
27
+ zipster!
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec'
5
+ require 'rspec/core/rake_task'
6
+
7
+ desc "Run all examples"
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.rspec_opts = %w[--color]
10
+ end
@@ -0,0 +1,3 @@
1
+ module Zipster
2
+ VERSION = "0.0.1"
3
+ end
data/lib/zipster.rb ADDED
@@ -0,0 +1,87 @@
1
+ require 'algorithms'
2
+
3
+ module Zipster
4
+ MAPPINGS = {
5
+ "AA" => ['340'],
6
+ "AE" => ['090'..'098'],
7
+ "AK" => ['995'..'999'],
8
+ "AL" => ['350'..'352','354'..'369'],
9
+ "AP" => ['962'..'966'],
10
+ "AR" => ['716'..'729'],
11
+ "AZ" => ['850'..'865'],
12
+ "CA" => ['900'..'961'],
13
+ "CO" => ['800'..'816'],
14
+ "CT" => ['060'..'069'],
15
+ "DC" => ['200','202'..'205','569'],
16
+ "DE" => ['197'..'199'],
17
+ "FL" => ['320'..'339','341','342','344','346','347','349'],
18
+ "GA" => ['300'..'319','398','399'],
19
+ "GU" => ['969'],
20
+ "HI" => ['967','968'],
21
+ "IA" => ['500'..'516','520'..'528'],
22
+ "ID" => ['832'..'838'],
23
+ "IL" => ['600'..'620','622'..'629'],
24
+ "IN" => ['460'..'479'],
25
+ "KS" => ['660'..'679'],
26
+ "KY" => ['400'..'418','420'..'427'],
27
+ "LA" => ['700'..'714'],
28
+ "MA" => ['010'..'027','055'],
29
+ "MD" => ['206'..'212','214'..'219'],
30
+ "ME" => ['039'..'049'],
31
+ "MI" => ['480'..'499'],
32
+ "MN" => ['550','551','553'..'567'],
33
+ "MO" => ['630'..'658'],
34
+ "MS" => ['386'..'397'],
35
+ "MT" => ['590'..'599'],
36
+ "NC" => ['270'..'289'],
37
+ "ND" => ['580'..'588'],
38
+ "NE" => ['680'..'693'],
39
+ "NH" => ['030'..'038'],
40
+ "NJ" => ['070'..'089'],
41
+ "NM" => ['870'..'884'],
42
+ "NV" => ['889'..'898'],
43
+ "NY" => ['005','100'..'149'],
44
+ "OH" => ['430'..'459'],
45
+ "OK" => ['730'..'749'],
46
+ "OR" => ['970'..'979'],
47
+ "PA" => ['150'..'196'],
48
+ "PR" => ['006'..'007','009'],
49
+ "RI" => ['028'..'029'],
50
+ "SC" => ['290'..'299'],
51
+ "SD" => ['570'..'577'],
52
+ "TN" => ['370'..'385'],
53
+ "TX" => ['750'..'799','885'],
54
+ "UT" => ['840'..'847'],
55
+ "VA" => ['201','220'..'246'],
56
+ "VI" => ['008'],
57
+ "VT" => ['050'..'054','056'..'059'],
58
+ "WA" => ['980'..'994'],
59
+ "WI" => ['530'..'532','534','535','537'..'542','544'..'549'],
60
+ "WV" => ['247'..'268'],
61
+ "WY" => ['820'..'831']
62
+ }
63
+
64
+
65
+ def self.zip_to_state(zip_code)
66
+ self.mapper[self.mapper.longest_prefix(zip_code)]
67
+ end
68
+
69
+ protected
70
+ def self.mapper
71
+ @mapper ||= self.build_mapper(MAPPINGS)
72
+ end
73
+
74
+ def self.get_mapping_for(zip)
75
+ self.mapper[self.mapper.longest_prefix(zip)]
76
+ end
77
+
78
+ def self.build_mapper(local_mappings)
79
+ local_mapper = Containers::Trie.new
80
+ local_mappings.each do |val, prefix|
81
+ prefix.map{|v| v.is_a?(Range) ? Array(v) : v}.flatten.each do |zip_prefix|
82
+ local_mapper.push(zip_prefix, val)
83
+ end
84
+ end
85
+ return local_mapper
86
+ end
87
+ end
@@ -0,0 +1,4 @@
1
+ require 'zipster'
2
+ # Requires supporting ruby files with custom matchers and macros, etc,
3
+ # in spec/support/ and its subdirectories.
4
+ Dir['./spec/support/**/*.rb'].map {|f| require f}
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Zipster" do
4
+
5
+ it "maps 65203 to missouri" do
6
+ Zipster.zip_to_state("65203").should == "MO"
7
+ end
8
+
9
+ it "maps 01001 to MA" do
10
+ Zipster.zip_to_state("01001").should == "MA"
11
+ end
12
+
13
+ it "maps 96169 to california" do
14
+ Zipster.zip_to_state("96169").should == "CA"
15
+ end
16
+
17
+ it "maps 66566 to Kansas" do
18
+ Zipster.zip_to_state("66566").should == "KS"
19
+ end
20
+ end
data/zipster.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "zipster/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "zipster"
7
+ s.version = Zipster::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Ethan Vizitei"]
10
+ s.email = ["ethan.vizitei@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Map zip codes to states}
13
+ s.description = %q{Give zipster a zip code, it will tell you what state it belongs to}
14
+
15
+ s.rubyforge_project = "zipster"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency(%q<rspec>)
23
+ s.add_runtime_dependency(%q<algorithms>)
24
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zipster
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Ethan Vizitei
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-24 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: algorithms
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ description: Give zipster a zip code, it will tell you what state it belongs to
50
+ email:
51
+ - ethan.vizitei@gmail.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ files:
59
+ - .gitignore
60
+ - Gemfile
61
+ - Gemfile.lock
62
+ - Rakefile
63
+ - lib/zipster.rb
64
+ - lib/zipster/version.rb
65
+ - spec/spec_helper.rb
66
+ - spec/zipster_spec.rb
67
+ - zipster.gemspec
68
+ has_rdoc: true
69
+ homepage: ""
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options: []
74
+
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ requirements: []
96
+
97
+ rubyforge_project: zipster
98
+ rubygems_version: 1.3.7
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Map zip codes to states
102
+ test_files:
103
+ - spec/spec_helper.rb
104
+ - spec/zipster_spec.rb