my_zipcode_gem 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -1,6 +1,6 @@
1
1
  h1. My Zipcode Gem
2
2
 
3
- Simple gem to handle zipcode lookups and related functionality.
3
+ Simple gem to handle zipcode lookups and related functionality. @rake zipcodes:update@ will automatically download and update your local zipcode database. Generates three models for extended zipcode functionality.
4
4
 
5
5
  h2. Installation
6
6
 
@@ -15,20 +15,20 @@ bc. rake bundle install
15
15
  Generate the models and populate the data:
16
16
 
17
17
  bc. rails g my_zipcode_gem:models
18
- rake db:migrate
19
- rake zipcodes:update
18
+ rake db:migrate
19
+ rake zipcodes:update
20
20
 
21
21
  You should now have three new tables and three new models, Zipcode, State, County.
22
22
 
23
23
  h2. Usage
24
24
 
25
25
  bc. zipcode = Zipcode.find_by_code '66206'
26
- zipcode.state.abbr # => 'KS'
27
- zipcode.city # => 'Shawnee Mission'
28
- zipcode.county.name # => 'Johnson'
29
- zipcode.lat.to_s # => '38.959356', it is actually a BigDecimal object converted to_s for documentation.
30
- zipcode.lon.to_s # => '-94.716155', ditto
31
- zipcode.is_geocoded? # => true, most if not all should be pre-geocoded.
26
+ zipcode.state.abbr # => 'KS'
27
+ zipcode.city # => 'Shawnee Mission'
28
+ zipcode.county.name # => 'Johnson'
29
+ zipcode.lat.to_s # => '38.959356', it is actually a BigDecimal object converted to_s for documentation.
30
+ zipcode.lon.to_s # => '-94.716155', ditto
31
+ zipcode.is_geocoded? # => true, most if not all should be pre-geocoded.
32
32
 
33
33
  You can also look for a zipcode from a city and state:
34
34
 
@@ -37,14 +37,14 @@ bc. Zipcode.find_by_city_state "Shawnee Mission", "KS"
37
37
  You can use State and County objects as follows:
38
38
 
39
39
  bc. state = State.find_by_abbr "MO"
40
- state.cities.count # => 963
41
- state.cities # gives you an sorted array of all cities for the state
42
- state.zipcodes.count # => 1195
43
- ...
44
- county = state.counties.first
45
- county.cities.count # => 5
46
- county.cities # gives you an sorted array of all cities for the county
47
- county.zipcodes.count # => 5
40
+ state.cities.count # => 963
41
+ state.cities # gives you a sorted array of all cities for the state
42
+ state.zipcodes.count # => 1195
43
+ ...
44
+ county = state.counties.first
45
+ county.cities.count # => 5
46
+ county.cities # gives you a sorted array of all cities for the county
47
+ county.zipcodes.count # => 5
48
48
 
49
49
  h3. Automatic JQuery/AJAX lookup
50
50
 
@@ -53,13 +53,13 @@ You can have a user enter a zipcode and automatically lookup their city, state a
53
53
  Put something like this in your view:
54
54
 
55
55
  bc. f.text_field :zip, :size => 5, :maxlength => 5, :class => 'zipcode_interactive'
56
- f.text_field :city, :size => 20, :maxlength => 60, :readonly => true
57
- f.text_field(:state, :size => 2, :maxlength => 2, :readonly => true)
58
- f.text_field(:county, :size => 20, :maxlength => 60, :readonly => true)
56
+ f.text_field :city, :size => 20, :maxlength => 60, :readonly => true
57
+ f.text_field(:state, :size => 2, :maxlength => 2, :readonly => true)
58
+ f.text_field(:county, :size => 20, :maxlength => 60, :readonly => true)
59
59
 
60
60
  Then add this to your application.js, but remember to replace [mycontrollername] with your own controller.
61
61
 
62
- bc. $(document).ready(function() {
62
+ bc. $(document).ready(function() {
63
63
  // Interactive Zipcodes
64
64
  $('input.zipcode_interactive').blur(function(data) {
65
65
  var elem_id = $(this).attr("id");
@@ -83,7 +83,7 @@ bc. $(document).ready(function() {
83
83
 
84
84
  You will also need a controller method similar to this, which will return the data to your form:
85
85
 
86
- bc. def get_zip_data
86
+ bc. def get_zip_data
87
87
  @zipcode = Zipcode.find_by_code(params[:code], :include => [:county, :state])
88
88
  if @zipcode
89
89
  @counties = County.find(:all, :conditions => [ "state_id = ?", @zipcode.county.state_id ])
@@ -93,4 +93,71 @@ namespace :zipcodes do
93
93
  Rake::Task['zipcodes:update_zipcodes'].invoke
94
94
  end
95
95
 
96
+ desc "Export US States to a .csv file"
97
+ task :export_states => :environment do
98
+ @states = State.order("name ASC")
99
+ csv_string = FasterCSV.generate do |csv|
100
+ csv << ["abbr", "name"]
101
+ @states.each do |state|
102
+ csv << [
103
+ state.abbr,
104
+ state.name
105
+ ]
106
+ end
107
+ end
108
+ filename = "all_us_states.csv"
109
+ open("#{Rails.root}/db/#{filename}", 'w') do |f|
110
+ f.write(csv_string)
111
+ end
112
+ end
113
+
114
+ desc "Export all US Counties to a .csv file"
115
+ task :export_counties => :environment do
116
+ @counties = County.order("name ASC")
117
+ csv_string = FasterCSV.generate do |csv|
118
+ csv << ["name", "state", "county_seat"]
119
+ @counties.each do |county|
120
+ csv << [
121
+ county.name,
122
+ county.state.abbr,
123
+ county.county_seat
124
+ ]
125
+ end
126
+ end
127
+ filename = "all_us_counties.csv"
128
+ open("#{Rails.root}/db/#{filename}", 'w') do |f|
129
+ f.write(csv_string)
130
+ end
131
+ end
132
+
133
+ desc "Export the zipcodes with county and state data"
134
+ task :export_zipcodes => :environment do
135
+ @zipcodes = Zipcode.order("code ASC")
136
+ csv_string = FasterCSV.generate do |csv|
137
+ csv << ["code", "city", "state", "county", "area_code", "lat", "lon"]
138
+ @zipcodes.each do |zip|
139
+ csv << [
140
+ zip.code,
141
+ zip.city,
142
+ zip.state.abbr,
143
+ zip.county.nil? ? '' : zip.county.name,
144
+ zip.area_code,
145
+ zip.lat,
146
+ zip.lon
147
+ ]
148
+ end
149
+ end
150
+ filename = "all_us_zipcodes.csv"
151
+ open("#{Rails.root}/db/#{filename}", 'w') do |f|
152
+ f.write(csv_string)
153
+ end
154
+ end
155
+
156
+ desc "Export zipcodes, states and counties tables"
157
+ task :export => :environment do
158
+ Rake::Task['zipcodes:export_states'].invoke
159
+ Rake::Task['zipcodes:export_counties'].invoke
160
+ Rake::Task['zipcodes:export_zipcodes'].invoke
161
+ end
162
+
96
163
  end
@@ -1,3 +1,3 @@
1
1
  module MyZipcodeGem
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency('rails', '3.0.3')
22
+ s.add_dependency('rails', '>= 3.0.0')
23
23
  s.add_dependency('rubigen', '1.5.6')
24
24
  s.add_dependency('fastercsv')
25
25
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_zipcode_gem
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Blackburn
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-03 00:00:00 -05:00
18
+ date: 2011-06-29 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -24,14 +24,14 @@ dependencies:
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - "="
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 1
29
+ hash: 7
30
30
  segments:
31
31
  - 3
32
32
  - 0
33
- - 3
34
- version: 3.0.3
33
+ - 0
34
+ version: 3.0.0
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
@@ -208,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
208
  requirements: []
209
209
 
210
210
  rubyforge_project: my_zipcode_gem
211
- rubygems_version: 1.6.2
211
+ rubygems_version: 1.5.3
212
212
  signing_key:
213
213
  specification_version: 3
214
214
  summary: A Ruby gem to handle all things zipcode.