Class: TaxJp::WithheldTaxes::BonusDbBuilder
- Defined in:
- lib/tax_jp/withheld_taxes/bonus_db_builder.rb
Instance Attribute Summary
Attributes inherited from DbBuilder
Instance Method Summary collapse
-
#initialize(db_path = nil) ⇒ BonusDbBuilder
constructor
A new instance of BonusDbBuilder.
- #run(options = {}) ⇒ Object
Constructor Details
#initialize(db_path = nil) ⇒ BonusDbBuilder
Returns a new instance of BonusDbBuilder.
6 7 8 |
# File 'lib/tax_jp/withheld_taxes/bonus_db_builder.rb', line 6 def initialize(db_path = nil) @db_path = db_path || TaxJp::WithheldTaxes::Bonus::DB_PATH end |
Instance Method Details
#run(options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tax_jp/withheld_taxes/bonus_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[1].to_i == 0 && row[2].to_i == 0 values = row.map{|col| TaxJp::Utils.normalize_amount(col)} ratio = values.shift / 100 values = values.map{|value| value < TaxJp::INTEGER_MAX ? value * 1000 : value } db.execute(insert_sql, [valid_from.to_s, valid_until.to_s, ratio] + values) end end end end |