Class: SingaporeCPFCalculator::BaseCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/singapore_cpf_calculator/base_calculator.rb

Overview

Base class for CPF calculators.

Direct Known Subclasses

Year2014::Base, Year2015::Base, Year2016::Base

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ordinary_wages:, additional_wages:) ⇒ BaseCalculator

Returns a new instance of BaseCalculator.



33
34
35
36
# File 'lib/singapore_cpf_calculator/base_calculator.rb', line 33

def initialize(ordinary_wages:, additional_wages:)
  @ordinary_wages = ordinary_wages
  @additional_wages = additional_wages
end

Class Method Details

.applies_to?(date, birthdate:) ⇒ true, false

Returns true if the calculator applies to the employee’s age.

Parameters:

  • age (Fixnum)

Returns:

  • (true, false)

    returns true if the calculator applies to the employee’s age.



8
9
10
# File 'lib/singapore_cpf_calculator/base_calculator.rb', line 8

def applies_to?(date, birthdate:)
  AgeGroup.get(date, birthdate: birthdate) == required_age_group
end

.calculate(ordinary_wages:, additional_wages:) ⇒ Hash

Returns the total, employee, employer amounts for the CPF contribution

Parameters:

  • ordinary_wages: (BigDecimal)

    Ordinary wages are wages due or granted in respect of employment and include allowances (e.g. food allowance and overtime payments) earned by an employee in the month and payable before the due date for payment of CPF contributions for that month.

  • additional_wages: (BigDecimal)

    Additional wages are wage supplements which are not granted wholly and exclusively for the month, such as annual bonus and leave pay. These and other incentive payments may be made at intervals of more than a month.

Returns:

  • (Hash)

    returns the total, employee, employer amounts for the CPF contribution



22
23
24
# File 'lib/singapore_cpf_calculator/base_calculator.rb', line 22

def calculate(ordinary_wages:, additional_wages:)
  new(ordinary_wages: ordinary_wages, additional_wages: additional_wages).calculate
end

Instance Method Details

#calculateHash

Returns the total, employee, employer amounts for the CPF contribution

Returns:

  • (Hash)

    returns the total, employee, employer amounts for the CPF contribution



39
40
41
42
# File 'lib/singapore_cpf_calculator/base_calculator.rb', line 39

def calculate
  CPFContribution.new total: total_contribution,
                      employee: employee_contribution
end