Class: TaxJp::DepreciationRates::DbBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/tax_jp/depreciation_rates/db_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(db_path = nil) ⇒ DbBuilder

Returns a new instance of DbBuilder.



5
6
7
# File 'lib/tax_jp/depreciation_rates/db_builder.rb', line 5

def initialize(db_path = nil)
  @db_path = db_path || TaxJp::DepreciationRate::DB_PATH
end

Instance Method Details

#run(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tax_jp/depreciation_rates/db_builder.rb', line 9

def run(options = {})
  with_database(options) do |db|
    Dir.glob(File.join(TaxJp::Utils.data_dir, '減価償却率', '減価償却率-*.tsv')).each do |filename|
      valid_from, valid_until = filename_to_date(filename)

      CSV.foreach(filename, :col_sep => "\t") do |row|
        next if row[0].to_i == 0
        db.execute(insert_sql, [valid_from, valid_until] + row)
      end
    end
  end
end