Skip to content

Commit 9b68460

Browse files
First cut of refactor
1 parent 6599105 commit 9b68460

26 files changed

Lines changed: 856 additions & 367 deletions

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
ZIP_CODES.txt
2-
zip_codes.zip
3-
zip_dump.csv
4-
zip_codes.db
51
/.bundle
62
/free_zipcode_data.sqlite3
73
/data
84
/build
5+
/stubs
6+
/vendor/bundle/

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--require spec_helper

.rubocop.yml

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
AllCops:
2+
TargetRubyVersion: 2.3
3+
24
# Include gemspec and Rakefile
35
Include:
46
- '**/*.gemspec'
@@ -15,6 +17,7 @@ AllCops:
1517
Exclude:
1618
- 'vendor/**/*'
1719
- 'stubs/**/*'
20+
- 'spec/support/shared_contexts/*'
1821

1922
# Checks formatting of special comments
2023
CommentAnnotation:
@@ -49,32 +52,16 @@ Style/RaiseArgs:
4952
Style/DoubleNegation:
5053
Enabled: false
5154

52-
Style/SignalException:
53-
EnforcedStyle: semantic
54-
55-
Style/ClassAndModuleChildren:
56-
Enabled: false
57-
58-
Style/MultilineMethodCallIndentation:
59-
EnforcedStyle: indented
60-
IndentationWidth: 4
61-
62-
Style/CaseIndentation:
63-
Enabled: false
64-
65-
Style/TrivialAccessors:
66-
Enabled: false
67-
68-
Style/NumericLiterals:
55+
Style/PerlBackrefs:
6956
Enabled: false
7057

7158
########################################
7259
# Lint Cops
7360

7461
Lint/Eval:
75-
Enabled: true
62+
Enabled: false
7663

77-
Lint/AssignmentInCondition:
64+
Lint/HandleExceptions:
7865
Enabled: false
7966

8067
########################################
@@ -85,7 +72,14 @@ Metrics/LineLength:
8572

8673
Metrics/MethodLength:
8774
CountComments: false # count full line comments?
88-
Max: 20
75+
Max: 30
8976

9077
Metrics/ClassLength:
9178
Max: 120
79+
80+
Metrics/AbcSize:
81+
Enabled: false
82+
83+
# rubocop:disable Metrics/AbcSize
84+
# rubocop:disable Metrics/MethodLength
85+
# rubocop:disable Metrics/BlockLength

Gemfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
source 'http://rubygems.org'
1+
# frozen_string_literal: true
22

3-
gem 'midwire_common'
4-
gem 'pry-nav'
5-
gem 'rake'
6-
gem 'rubyzip', '~> 1.2.1'
7-
gem 'sqlite3'
3+
source 'https://rubygems.org'
4+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5+
6+
gemspec

Gemfile.lock

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,79 @@
1+
PATH
2+
remote: .
3+
specs:
4+
free_zipcode_data (1.0.0)
5+
colored (~> 1.2)
6+
kiba (~> 2.0)
7+
rubyzip (~> 1.2)
8+
sqlite3 (~> 1.3)
9+
trollop (~> 2.1)
10+
111
GEM
2-
remote: http://rubygems.org/
12+
remote: https://rubygems.org/
313
specs:
14+
ast (2.4.0)
415
coderay (1.1.2)
16+
colored (1.2)
17+
diff-lcs (1.3)
18+
docile (1.3.0)
19+
json (2.1.0)
20+
kiba (2.0.0)
521
method_source (0.8.2)
6-
midwire_common (0.1.16)
7-
thor (~> 0.19)
22+
parallel (1.12.1)
23+
parser (2.5.1.0)
24+
ast (~> 2.4.0)
25+
powerpack (0.1.1)
826
pry (0.10.4)
927
coderay (~> 1.1.0)
1028
method_source (~> 0.8.1)
1129
slop (~> 3.4)
1230
pry-nav (0.2.4)
1331
pry (>= 0.9.10, < 0.11.0)
32+
rainbow (3.0.0)
1433
rake (12.2.1)
34+
rspec (3.7.0)
35+
rspec-core (~> 3.7.0)
36+
rspec-expectations (~> 3.7.0)
37+
rspec-mocks (~> 3.7.0)
38+
rspec-core (3.7.1)
39+
rspec-support (~> 3.7.0)
40+
rspec-expectations (3.7.0)
41+
diff-lcs (>= 1.2.0, < 2.0)
42+
rspec-support (~> 3.7.0)
43+
rspec-mocks (3.7.0)
44+
diff-lcs (>= 1.2.0, < 2.0)
45+
rspec-support (~> 3.7.0)
46+
rspec-support (3.7.1)
47+
rubocop (0.55.0)
48+
parallel (~> 1.10)
49+
parser (>= 2.5)
50+
powerpack (~> 0.1)
51+
rainbow (>= 2.2.2, < 4.0)
52+
ruby-progressbar (~> 1.7)
53+
unicode-display_width (~> 1.0, >= 1.0.1)
54+
ruby-progressbar (1.9.0)
1555
rubyzip (1.2.1)
56+
simplecov (0.16.1)
57+
docile (~> 1.1)
58+
json (>= 1.8, < 3)
59+
simplecov-html (~> 0.10.0)
60+
simplecov-html (0.10.2)
1661
slop (3.6.0)
17-
sqlite3 (1.3.11)
18-
thor (0.19.1)
62+
sqlite3 (1.3.13)
63+
trollop (2.1.2)
64+
unicode-display_width (1.3.2)
1965

2066
PLATFORMS
2167
ruby
2268

2369
DEPENDENCIES
24-
midwire_common
25-
pry-nav
26-
rake
27-
rubyzip (~> 1.2.1)
28-
sqlite3
70+
bundler (~> 1.16)
71+
free_zipcode_data!
72+
pry-nav (~> 0.2)
73+
rake (~> 12.0)
74+
rspec (~> 3.7)
75+
rubocop
76+
simplecov
2977

3078
BUNDLED WITH
31-
1.15.4
79+
1.16.1

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ create table zipcodes (
9090

9191
Both `lat` and `lon`, geocodes, are populated for each zipcode record.
9292

93+
## Development
94+
95+
If you want to run the specs or do development work, set `GEM_ENV='development'`
96+
9397
## Data License
9498

9599
The zipcode data is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</a>, carried forward from [GeoNames](http://www.geonames.org).<br />

bin/free_zipcode_data

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'rubygems'
4+
require 'bundler/setup'
5+
6+
require 'free_zipcode_data'
7+
require 'free_zipcode_data/runner'
8+
9+
FreeZipcodeData::Runner.instance.start

country_lookup_table.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ AX:
1010
AL:
1111
:name: Albania
1212
:alpha3: ALB
13-
:iso: 008
13+
:iso: '008'
1414
DZ:
1515
:name: Algeria
1616
:alpha3: DZA

free_zipcode_data.gemspec

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
# coding: utf-8
3+
4+
lib = File.expand_path('../lib', __FILE__)
5+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6+
require 'free_zipcode_data/version'
7+
8+
Gem::Specification.new do |spec|
9+
spec.name = 'free_zipcode_data'
10+
spec.version = FreeZipcodeData::VERSION
11+
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
15+
spec.homepage = 'https://github.com/midwire/free_zipcode_data'
16+
spec.license = 'MIT'
17+
18+
spec.required_ruby_version = '>= 2.3.0'
19+
spec.files = `git ls-files -z`.split("\x0")
20+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22+
spec.require_paths = ['lib']
23+
24+
spec.add_development_dependency 'bundler', '~> 1.16'
25+
spec.add_development_dependency 'pry-nav', '~> 0.2'
26+
spec.add_development_dependency 'rake', '~> 12.0'
27+
spec.add_development_dependency 'rspec', '~> 3.7'
28+
spec.add_development_dependency 'rubocop'
29+
spec.add_development_dependency 'simplecov'
30+
31+
spec.add_runtime_dependency 'colored', '~> 1.2'
32+
spec.add_runtime_dependency 'kiba', '~> 2.0'
33+
spec.add_runtime_dependency 'rubyzip', '~> 1.2'
34+
spec.add_runtime_dependency 'sqlite3', '~> 1.3'
35+
spec.add_runtime_dependency 'trollop', '~> 2.1'
36+
end

lib/etl/common.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'csv_source'
4+
require_relative '../free_zipcode_data/country_table'
5+
require_relative '../free_zipcode_data/state_table'
6+
require_relative '../free_zipcode_data/county_table'
7+
require_relative '../free_zipcode_data/zipcode_table'
8+
9+
def show_me
10+
transform do |row|
11+
ap row
12+
row
13+
end
14+
end
15+
16+
def limit(count)
17+
count = Integer(count || -1)
18+
return if count == -1
19+
transform do |row|
20+
@counter ||= 0
21+
@counter += 1
22+
@counter > count ? nil : row
23+
end
24+
end

0 commit comments

Comments
 (0)