class InsuranceJP

Attributes

table[R]

Public Class Methods

new(dir_path, area=nil, date=nil) click to toggle source

load config

# File lib/luca_salary/jp/insurance.rb, line 10
def initialize(dir_path, area=nil, date=nil)
  @pjdir = Pathname(dir_path) + 'dict'
  @area = area
  @date = date
  @table = load_table
end

Public Instance Methods

health_insurance_salary(rank) click to toggle source
# File lib/luca_salary/jp/insurance.rb, line 22
def health_insurance_salary(rank)
  round6(select_health_insurance(rank).dig('insurance_elder_salary'))
end
load_table() click to toggle source
# File lib/luca_salary/jp/insurance.rb, line 17
def load_table
  file_name = @pjdir + select_active_filename
  JSON.parse(File.read(file_name.to_s))
end
pension_salary(rank) click to toggle source
# File lib/luca_salary/jp/insurance.rb, line 26
def pension_salary(rank)
  round6(select_pension(rank).dig('pension_salary'))
end
select_health_insurance(rank) click to toggle source
# File lib/luca_salary/jp/insurance.rb, line 30
def select_health_insurance(rank)
  @table['fee'].filter{|h| h['rank'] == rank}.first
end
select_pension(rank) click to toggle source
# File lib/luca_salary/jp/insurance.rb, line 34
def select_pension(rank)
  @table['fee'].filter{|h| h['pension_rank'] == rank}.first
end

Private Instance Methods

load_json() click to toggle source
# File lib/luca_salary/jp/insurance.rb, line 50
def load_json
  table_list = [].tap do |a|
    open_tables do |f, name|
      data = JSON.parse(f.read)
      a << [Date.parse(data['effective_date']), name]
    end
  end
end
open_tables() { |f, file_name| ... } click to toggle source
# File lib/luca_salary/jp/insurance.rb, line 59
def open_tables
  Dir.chdir(@pjdir.to_s) do
    Dir.glob("*.json").each do |file_name|
      File.open(file_name, 'r') {|f| yield(f, file_name)}
    end
  end
end
round6(num) click to toggle source
# File lib/luca_salary/jp/insurance.rb, line 40
def round6(num)
  BigDecimal(num).round(0, BigDecimal::ROUND_HALF_DOWN).to_i
end
select_active_filename() click to toggle source

TODO: need selection logic

# File lib/luca_salary/jp/insurance.rb, line 45
def select_active_filename
  list = load_json
  list.first[1]
end