class SingaporeCPFCalculator::SPRStatus

Attributes

current_date[R]
status_start_date[R]

Public Class Methods

get(current_date, status_start_date:) click to toggle source
# File lib/singapore_cpf_calculator/spr_status.rb, line 6
def get(current_date, status_start_date:)
  new(current_date, status_start_date: status_start_date).get
end
new(current_date, status_start_date:) click to toggle source
# File lib/singapore_cpf_calculator/spr_status.rb, line 11
def initialize(current_date, status_start_date:)
  @current_date = current_date
  @status_start_date = status_start_date
end

Public Instance Methods

get() click to toggle source
# File lib/singapore_cpf_calculator/spr_status.rb, line 16
def get
  case
  when spr1_start <= current_date && current_date <= spr1_end then :SPR1
  when spr2_start <= current_date && current_date <= spr2_end then :SPR2
  when spr3_start <= current_date then :SPR3
  else
    nil # could not be determined
  end
end

Private Instance Methods

spr1_end() click to toggle source
# File lib/singapore_cpf_calculator/spr_status.rb, line 34
def spr1_end
  @spr1_end ||= (spr1_start.beginning_of_month.advance years: 1).end_of_month
end
spr1_start() click to toggle source
# File lib/singapore_cpf_calculator/spr_status.rb, line 30
def spr1_start
  status_start_date
end
spr2_end() click to toggle source
# File lib/singapore_cpf_calculator/spr_status.rb, line 42
def spr2_end
  @spr2_end ||= spr2_start.dup.advance(months: 11).end_of_month
end
spr2_start() click to toggle source
# File lib/singapore_cpf_calculator/spr_status.rb, line 38
def spr2_start
  @spr2_start ||= spr1_end.beginning_of_month.advance months: 1
end
spr3_start() click to toggle source
# File lib/singapore_cpf_calculator/spr_status.rb, line 46
def spr3_start
  spr2_end.beginning_of_month.advance(months: 1)
end