Class: BenefitsReceivedCalculatorService

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

Overview

A calculator service for the benefits received for an individual or couple

Constant Summary collapse

MY_FIELDS =
[:benefits_received].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(attrs) ⇒ BenefitsReceivedCalculatorService

Returns a new instance of BenefitsReceivedCalculatorService


6
7
8
9
10
# File 'app/services/benefits_received_calculator_service.rb', line 6

def initialize(attrs)
  attrs = attrs.dup # Dont modify inputs
  attrs[:benefits_received] = attrs[:benefits_received].map(&:to_sym) if attrs[:benefits_received].is_a?(Array)
  super(attrs)
end

Class Method Details

.fields_required(inputs) ⇒ Object


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

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

Instance Method Details

#callObject


12
13
14
15
# File 'app/services/benefits_received_calculator_service.rb', line 12

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

#valid?Boolean

Returns:

  • (Boolean)

17
18
19
# File 'app/services/benefits_received_calculator_service.rb', line 17

def valid?
  inputs[:benefits_received].is_a?(Array)
end