Class: SingaporeCPFCalculator::CPFContribution

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

Overview

Result object that describes the total, employee, and employer contribution.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(total:, employee:, ow_subject_to_cpf:, aw_subject_to_cpf:) ⇒ CPFContribution

Returns a new instance of CPFContribution.

Parameters:

  • total (BigDecimal)

    the total contribution amount

  • employee (BigDecimal)

    the employee contribution amount

  • ow_subject_to_cpf (BigDecimal)

    Ordinary Wages which were subject to CPF

  • aw_subject_to_cpf (BigDecimal)

    Additional Wages which were subject to CPF



13
14
15
16
17
18
# File 'lib/singapore_cpf_calculator/cpf_contribution.rb', line 13

def initialize(total:, employee:, ow_subject_to_cpf:, aw_subject_to_cpf:)
  @total = total
  @employee = employee
  @ow_subject_to_cpf = ow_subject_to_cpf
  @aw_subject_to_cpf = aw_subject_to_cpf
end

Instance Attribute Details

#aw_subject_to_cpfBigDecimal (readonly)

Returns:

  • (BigDecimal)


7
8
9
# File 'lib/singapore_cpf_calculator/cpf_contribution.rb', line 7

def aw_subject_to_cpf
  @aw_subject_to_cpf
end

#employeeBigDecimal (readonly)

Returns:

  • (BigDecimal)


7
8
9
# File 'lib/singapore_cpf_calculator/cpf_contribution.rb', line 7

def employee
  @employee
end

#ow_subject_to_cpfBigDecimal (readonly)

Returns:

  • (BigDecimal)


7
8
9
# File 'lib/singapore_cpf_calculator/cpf_contribution.rb', line 7

def ow_subject_to_cpf
  @ow_subject_to_cpf
end

#totalBigDecimal (readonly)

Returns:

  • (BigDecimal)


7
8
9
# File 'lib/singapore_cpf_calculator/cpf_contribution.rb', line 7

def total
  @total
end

Instance Method Details

#==(other) ⇒ TrueClass, FalseClass

Parameters:

Returns:

  • (TrueClass, FalseClass)


27
28
29
30
31
# File 'lib/singapore_cpf_calculator/cpf_contribution.rb', line 27

def ==(other)
  other.kind_of?(CPFContribution) && total == other.total && employee == other.employee &&
    (ow_subject_to_cpf == other.ow_subject_to_cpf) &&
    (aw_subject_to_cpf == other.aw_subject_to_cpf)
end

#employerBigDecimal

Returns difference between the total and employee contributions.

Returns:

  • (BigDecimal)

    difference between the total and employee contributions



21
22
23
# File 'lib/singapore_cpf_calculator/cpf_contribution.rb', line 21

def employer
  @employer ||= total - employee
end

#inspectObject



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

def inspect
  {total: total.to_s, employee: employee.to_s,
   ow_subject_to_cpf: ow_subject_to_cpf.to_s, aw_subject_to_cpf: aw_subject_to_cpf.to_s}.to_json
end