Skip to content

Commit 1e9ec0f

Browse files
authored
Merge pull request #8 from midwire/feature/5-finish-refactor
Finish refactor
2 parents ba54bc6 + 50cd649 commit 1e9ec0f

17 files changed

Lines changed: 337 additions & 36 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/build
55
/stubs
66
/vendor/bundle/
7+
/pkg

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ CommentAnnotation:
3131
########################################
3232
# Style Cops
3333

34+
Style/ClassVars:
35+
Enabled: false
36+
3437
Style/Documentation:
3538
Enabled: false
3639

CHANGELOG

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*1.0.1* (April 23, 2018)
2+
3+
* Made it a gem with a command line executable bin/free_zipcode_data
4+
* Use Kiba for ETL
5+
* Support user switches for various options including custom table names and generating .csv files
6+
* Use in-memory SQLite database to create the tables, then save it as a file on disk
7+
* Separate concerns for each table
8+
* Add a progressbar with ETA
9+
* Fix a bug when looking up state_id
10+
* Add a ‘name’ index on states table
11+
* Add a switch to generate individual .csv files [--generate-files]
12+
* Add a switch to overwrite [--clobber] downloaded and generated .csv files

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## How to contribute to jsonapi_rspec
1+
## How to contribute to free_zipcode_data
22

33
#### **Did you find a bug?**
44

Gemfile.lock

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
PATH
22
remote: .
33
specs:
4-
free_zipcode_data (1.0.0)
4+
free_zipcode_data (1.0.1)
55
colored (~> 1.2)
66
kiba (~> 2.0)
7+
ruby-progressbar (~> 1.9)
78
rubyzip (~> 1.2)
89
sqlite3 (~> 1.3)
910
trollop (~> 2.1)
@@ -51,6 +52,7 @@ GEM
5152
rainbow (>= 2.2.2, < 4.0)
5253
ruby-progressbar (~> 1.7)
5354
unicode-display_width (~> 1.0, >= 1.0.1)
55+
ruby-prof (0.17.0)
5456
ruby-progressbar (1.9.0)
5557
rubyzip (1.2.1)
5658
simplecov (0.16.1)
@@ -72,8 +74,9 @@ DEPENDENCIES
7274
pry-nav (~> 0.2)
7375
rake (~> 12.0)
7476
rspec (~> 3.7)
75-
rubocop
76-
simplecov
77+
rubocop (~> 0.55)
78+
ruby-prof (~> 0.17)
79+
simplecov (~> 0.16)
7780

7881
BUNDLED WITH
7982
1.16.1

Rakefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
# frozen_string_literal: true
2+
13
require 'rubygems'
24
require 'bundler/setup'
35

46
require 'rake'
57
Dir['lib/tasks/**/*.rake'].sort.each { |ext| load ext }
8+
9+
# Install rubygem tasks
10+
Bundler::GemHelper.install_tasks

free_zipcode_data.gemspec

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ lib = File.expand_path('../lib', __FILE__)
55
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
66
require 'free_zipcode_data/version'
77

8+
# rubocop:disable Metrics/BlockLength
89
Gem::Specification.new do |spec|
910
spec.name = 'free_zipcode_data'
1011
spec.version = FreeZipcodeData::VERSION
1112
spec.authors = ['Chris Blackburn', 'Chris McKnight']
12-
spec.email = ['87a1779b@opayq.com']
13-
spec.summary = 'Free US postal codes in CSV and SQLite3 format.'
14-
spec.description = spec.summary
13+
spec.email = ['87a1779b@opayq.com', 'fixme@mcknight.bogus']
14+
spec.summary = 'Free US and world-wide postal codes in SQLite and CSV format'
15+
spec.description = <<~STRING
16+
Free US and world-wide postal codes in SQLite and CSV format.
17+
Automated zipcode/postal code aggregation and processing for any needs.
18+
STRING
1519
spec.homepage = 'https://github.com/midwire/free_zipcode_data'
1620
spec.license = 'MIT'
1721

@@ -25,12 +29,15 @@ Gem::Specification.new do |spec|
2529
spec.add_development_dependency 'pry-nav', '~> 0.2'
2630
spec.add_development_dependency 'rake', '~> 12.0'
2731
spec.add_development_dependency 'rspec', '~> 3.7'
28-
spec.add_development_dependency 'rubocop'
29-
spec.add_development_dependency 'simplecov'
32+
spec.add_development_dependency 'rubocop', '~> 0.55'
33+
spec.add_development_dependency 'ruby-prof', '~> 0.17'
34+
spec.add_development_dependency 'simplecov', '~> 0.16'
3035

3136
spec.add_runtime_dependency 'colored', '~> 1.2'
3237
spec.add_runtime_dependency 'kiba', '~> 2.0'
38+
spec.add_runtime_dependency 'ruby-progressbar', '~> 1.9'
3339
spec.add_runtime_dependency 'rubyzip', '~> 1.2'
3440
spec.add_runtime_dependency 'sqlite3', '~> 1.3'
3541
spec.add_runtime_dependency 'trollop', '~> 2.1'
3642
end
43+
# rubocop:enable Metrics/BlockLength

lib/etl/free_zipcode_data_job.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def setup(country_file, database, logger, options)
3030
database: database,
3131
tablename: options[:zipcode_tablename]
3232

33+
post_process do
34+
logger.verbose('Finished generating table data...')
35+
end
3336
end
3437
end
3538
end

lib/free_zipcode_data/country_table.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def write(row)
3939
rescue SQLite3::ConstraintException
4040
# Swallow duplicates
4141
end
42+
43+
update_progress
4244
end
4345
end
4446
end

lib/free_zipcode_data/county_table.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ def build
2525

2626
def write(row)
2727
return nil unless row[:county]
28-
state_id = get_state_id(row[:short_state])
29-
raise "Could not find state: #{row[:short_state]}" unless state_id
28+
state_id = get_state_id(row[:short_state], row[:state])
29+
return nil unless state_id
30+
3031
sql = <<-SQL
3132
INSERT INTO counties (state_id, abbr, name)
3233
VALUES ('#{state_id}',
@@ -42,6 +43,8 @@ def write(row)
4243
rescue StandardError => err
4344
raise "Please file an issue at #{ISSUE_URL}: [#{err}] -> SQL: [#{sql}]"
4445
end
46+
47+
update_progress
4548
end
4649
end
4750
end

0 commit comments

Comments
 (0)