class Philhealth

Constants

MULTIPLIER

Public Instance Methods

call() click to toggle source
# File lib/philhealth_calculator.rb, line 9
def call
  load_csv
  set_bracket
  set_monthly_premium
  set_employer_share
  set_personal_share
  deduct_excess_centavo_from_employer if with_excess_centavo?(@employer_share)
  return_contributions
end

Private Instance Methods

bracket_1?() click to toggle source
# File lib/philhealth_calculator.rb, line 39
def bracket_1?
  @bracket == @csv[0]
end
bracket_2?() click to toggle source
# File lib/philhealth_calculator.rb, line 43
def bracket_2?
  @bracket == @csv[1]
end
bracket_3?() click to toggle source
# File lib/philhealth_calculator.rb, line 47
def bracket_3?
  @bracket == @csv[2]
end
deduct_excess_centavo_from_employer() click to toggle source
# File lib/philhealth_calculator.rb, line 63
def deduct_excess_centavo_from_employer
  @employer_share += 0.005
  @personal_share -= 0.005
end
load_csv() click to toggle source

read CSV then create array of hashes for each row

# File lib/philhealth_calculator.rb, line 22
def load_csv
  @csv = get_rows_from_csv("philhealth_table.csv")
end
return_contributions() click to toggle source
# File lib/philhealth_calculator.rb, line 59
def return_contributions
  { employer_share: @employer_share, personal_share: @personal_share }
end
set_bracket() click to toggle source
# File lib/philhealth_calculator.rb, line 26
def set_bracket
  @bracket = @csv.select { |row| row["min"] <= @compensation && row["max"] >= @compensation }.first
end
set_employer_share() click to toggle source
# File lib/philhealth_calculator.rb, line 51
def set_employer_share
  @employer_share = @monthly_premium / 2
end
set_monthly_premium() click to toggle source
# File lib/philhealth_calculator.rb, line 30
def set_monthly_premium
  case
  when bracket_1?, bracket_3?
    @monthly_premium = @bracket["monthly_premium"]
  when bracket_2?
    @monthly_premium = (@compensation * MULTIPLIER).round(2)
  end
end
set_personal_share() click to toggle source
# File lib/philhealth_calculator.rb, line 55
def set_personal_share
  @personal_share = @monthly_premium / 2
end