Class: TaxJp::WithheldTaxes::MonthlyDbBuilder
- Defined in:
- lib/tax_jp/withheld_taxes/monthly_db_builder.rb
Instance Attribute Summary
Attributes inherited from DbBuilder
Instance Method Summary collapse
-
#initialize(db_path = nil) ⇒ MonthlyDbBuilder
constructor
A new instance of MonthlyDbBuilder.
- #run(options = {}) ⇒ Object
Constructor Details
#initialize(db_path = nil) ⇒ MonthlyDbBuilder
Returns a new instance of MonthlyDbBuilder.
6 7 8 |
# File 'lib/tax_jp/withheld_taxes/monthly_db_builder.rb', line 6 def initialize(db_path = nil) @db_path = db_path || TaxJp::WithheldTax::MONTHLY_DB_PATH end |
Instance Method Details
#run(options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/tax_jp/withheld_taxes/monthly_db_builder.rb', line 10 def run( = {}) with_database() do |db| Dir.glob(File.join(TaxJp::Utils.data_dir, '源泉徴収税', '源泉徴収税月額-*.tsv')).each do |filename| valid_from, valid_until = TaxJp::Utils.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.to_s, valid_until.to_s] + row.map{|col| normalize_amount(col)}) end end end end |