Class: TaxJp::SocialInsurances::DbBuilder
- Inherits:
-
Object
- Object
- TaxJp::SocialInsurances::DbBuilder
- Defined in:
- lib/tax_jp/social_insurances/db_builder.rb
Instance Method Summary collapse
-
#initialize(db_path = nil) ⇒ DbBuilder
constructor
A new instance of DbBuilder.
- #run(options = {}) ⇒ Object
Constructor Details
#initialize(db_path = nil) ⇒ DbBuilder
Returns a new instance of DbBuilder.
6 7 8 |
# File 'lib/tax_jp/social_insurances/db_builder.rb', line 6 def initialize(db_path = nil) @db_path = db_path || TaxJp::SocialInsurance::DB_PATH end |
Instance Method Details
#run(options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tax_jp/social_insurances/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 = filename_to_date(filename) CSV.foreach(filename, :col_sep => "\t") do |row| next if row[0].to_i == 0 db.execute(insert_sql_grade, [valid_from, valid_until] + row.map{|col| normalize_amount(col)}) end end 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 unless row[1].to_f > 0 values = [valid_from, valid_until] values << TaxJp::Prefecture.find_by_name(row.shift).code values += row.map{|col| (col.to_f * 0.01).round(4) } db.execute(insert_sql_health_insurance, values) end end Dir.glob(File.join(TaxJp::Utils.data_dir, '社会保険料', '厚生年金.tsv')).each do |filename| CSV.foreach(filename, :col_sep => "\t") do |row| next unless row[2].to_f > 0 values = [] values << row.shift values << row.shift values += row.map{|col| (col.to_f * 0.01).round(5) } db.execute(insert_sql_welfare_pensions, values) end end end end |