Class: FreeZipcodeData::Runner
- Inherits:
-
Object
- Object
- FreeZipcodeData::Runner
- Defined in:
- lib/free_zipcode_data/runner.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
-
.instance ⇒ Object
Make a singleton but allow the class to be instantiated for easier testing.
Instance Method Summary collapse
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #start ⇒ Object
Constructor Details
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
14 15 16 |
# File 'lib/free_zipcode_data/runner.rb', line 14 def logger @logger end |
#options ⇒ Object
Returns the value of attribute options.
14 15 16 |
# File 'lib/free_zipcode_data/runner.rb', line 14 def @options end |
Class Method Details
.instance ⇒ Object
Make a singleton but allow the class to be instantiated for easier testing
17 18 19 |
# File 'lib/free_zipcode_data/runner.rb', line 17 def self.instance @instance || new end |
Instance Method Details
#start ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/free_zipcode_data/runner.rb', line 25 def start start_time = Time.now opt = FreeZipcodeData::Options.instance opt.initialize_hash(collect_args) @options = opt.hash logger.info("Starting FreeZipcodeData v#{VERSION}...".green) datasource = DataSource.new(.country) datasource.download db_file = File.join(.work_dir, 'free_zipcode_data.sqlite3') database = SqliteRam.new(db_file) line_count = datasource_line_count(datasource.datafile) (database.conn, line_count) %i[country state county zipcode].each { |t| initialize_table(t, database) } extract_transform_load(datasource, database) logger.info("Saving database to disk '#{db_file}'...") database.save_to_disk if .generate_files logger.info('Generating .csv files...') database.dump_tables(.work_dir) end elapsed = Time.at(Time.now - start_time).utc.strftime('%H:%M:%S') logger.info("Processed #{line_count} zipcodes in [#{elapsed}].".yellow) end |