Class: DisposableCapitalCalculatorService

Inherits:
BaseCalculatorService show all
Defined in:
app/services/disposable_capital_calculator_service.rb

Overview

A calculator service for the disposable capital of an individual or couple

Uses an internal lookup table to decide based on the age (of the eldest), the court fee, and the disposable_capital of the person or couple.

Constant Summary collapse

FEE_TABLE =
[
  { age: 1..60, fee: 1..1000, disposable_capital: 3000 }.freeze,
  { age: 1..60, fee: 1001..1335, disposable_capital: 4000 }.freeze,
  { age: 1..60, fee: 1336..1665, disposable_capital: 5000 }.freeze,
  { age: 1..60, fee: 1666..2000, disposable_capital: 6000 }.freeze,
  { age: 1..60, fee: 2001..2330, disposable_capital: 7000 }.freeze,
  { age: 1..60, fee: 2331..4000, disposable_capital: 8000 }.freeze,
  { age: 1..60, fee: 4001..5000, disposable_capital: 10000 }.freeze,
  { age: 1..60, fee: 5001..6000, disposable_capital: 12000 }.freeze,
  { age: 1..60, fee: 6001..7000, disposable_capital: 14000 }.freeze,
  { age: 1..60, fee: 7001..Float::INFINITY, disposable_capital: 16000 }.freeze,
  { age: 61..200, fee: 1..Float::INFINITY, disposable_capital: 16000 }.freeze
].freeze
MY_FIELDS =
[:fee, :date_of_birth, :partner_date_of_birth, :disposable_capital].freeze

Instance Attribute Summary

Attributes inherited from BaseCalculatorService

#available_help, #messages, #remission

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCalculatorService

call, #final_decision?, identifier

Constructor Details

#initialize(age_service: AgeService, **args) ⇒ DisposableCapitalCalculatorService

Returns a new instance of DisposableCapitalCalculatorService


21
22
23
24
# File 'app/services/disposable_capital_calculator_service.rb', line 21

def initialize(age_service: AgeService, **args)
  self.age_service = age_service
  super args
end

Class Method Details

.fields_required(inputs) ⇒ Object


38
39
40
# File 'app/services/disposable_capital_calculator_service.rb', line 38

def self.fields_required(inputs, *)
  MY_FIELDS - inputs.keys
end

Instance Method Details

#callObject


26
27
28
29
# File 'app/services/disposable_capital_calculator_service.rb', line 26

def call
  throw :invalid_inputs, self unless valid?
  process_inputs
end

#valid?Boolean

Returns:

  • (Boolean)

31
32
33
34
35
36
# File 'app/services/disposable_capital_calculator_service.rb', line 31

def valid?
  date_of_birth_valid? &&
    partner_date_of_birth_valid? &&
    fee_valid? &&
    disposable_capital_valid?
end