Skip to content

Commit 536cdfe

Browse files
authored
Merge pull request #13 from srghma/develop
fix No such file or directory @ rb_sysopen - country_lookup_table.yml
2 parents 1a18feb + ecf42d4 commit 536cdfe

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

lib/free_zipcode_data/db_table.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ def update_progress
2424
private
2525

2626
def country_lookup_table
27-
@country_lookup_table ||= YAML.load_file('country_lookup_table.yml')
27+
@country_lookup_table ||=
28+
begin
29+
path = File.expand_path('../../country_lookup_table.yml', __dir__)
30+
YAML.load_file(path)
31+
end
2832
end
2933

3034
def select_first(sql)

lib/free_zipcode_data/runner.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def start
3535

3636
db_file = File.join(options.work_dir, 'free_zipcode_data.sqlite3')
3737
database = SqliteRam.new(db_file)
38-
configure_meta(database.conn, datasource.datafile)
38+
39+
line_count = datasource_line_count(datasource.datafile)
40+
configure_meta(database.conn, line_count)
3941

4042
%i[country state county zipcode].each { |t| initialize_table(t, database) }
4143

@@ -50,7 +52,7 @@ def start
5052
end
5153

5254
elapsed = Time.at(Time.now - start_time).utc.strftime('%H:%M:%S')
53-
logger.info("Processed #{datasource_line_count} zipcodes in [#{elapsed}].".yellow)
55+
logger.info("Processed #{line_count} zipcodes in [#{elapsed}].".yellow)
5456
end
5557

5658
private
@@ -67,14 +69,12 @@ def initialize_table(table_sym, database)
6769
end
6870

6971
def datasource_line_count(filename)
70-
@datasource_line_count ||= begin
71-
count = File.foreach(filename).inject(0) { |c, _line| c + 1 }
72-
logger.verbose("Processing #{count} zipcodes in '#{filename}'...")
73-
count
74-
end
72+
count = File.foreach(filename).inject(0) { |c, _line| c + 1 }
73+
logger.verbose("Processing #{count} zipcodes in '#{filename}'...")
74+
count
7575
end
7676

77-
def configure_meta(database, datasource)
77+
def configure_meta(database, line_count)
7878
schema = <<-SQL
7979
create table meta (
8080
id integer not null primary key,
@@ -86,7 +86,7 @@ def configure_meta(database, datasource)
8686

8787
sql = <<-SQL
8888
INSERT INTO meta (name, value)
89-
VALUES ('line_count', #{datasource_line_count(datasource)})
89+
VALUES ('line_count', #{line_count})
9090
SQL
9191
database.execute(sql)
9292
end

0 commit comments

Comments
 (0)