Module: CalculationFeedbackHelper

Defined in:
app/helpers/calculation_feedback_helper.rb

Instance Method Summary collapse

Instance Method Details

#calculation_contribution(calculation) ⇒ String

Presents the calculation citizen contribution in the correct format

Parameters:

  • calculation (Calculation)

    The calculation to get the contribution from

Returns:

  • (String)

    The text to display


83
84
85
# File 'app/helpers/calculation_feedback_helper.rb', line 83

def calculation_contribution(calculation)
  number_to_currency(calculation.inputs[:fee] - calculation.remission, precision: 0, unit: '£')
end

#calculation_disposable_capital(calculation) ⇒ String

Presents the calculation disposable capital in the correct format

Parameters:

  • calculation (Calculation)

    The calculation to get the disposable capital from

Returns:

  • (String)

    The text to display


101
102
103
# File 'app/helpers/calculation_feedback_helper.rb', line 101

def calculation_disposable_capital(calculation)
  number_to_currency(calculation.inputs[:disposable_capital], precision: 0, unit: '£')
end

#calculation_fee(calculation) ⇒ String

Presents the calculation fee in the correct format

Parameters:

  • calculation (Calculation)

    The calculation to get the fee from

Returns:

  • (String)

    The text to display


65
66
67
# File 'app/helpers/calculation_feedback_helper.rb', line 65

def calculation_fee(calculation)
  number_to_currency(calculation.inputs[:fee], precision: 0, unit: '£')
end

#calculation_remission(calculation) ⇒ String

Presents the calculation remission in the correct format

Parameters:

  • calculation (Calculation)

    The calculation to get the remission from

Returns:

  • (String)

    The text to display


74
75
76
# File 'app/helpers/calculation_feedback_helper.rb', line 74

def calculation_remission(calculation)
  number_to_currency(calculation.remission, precision: 0, unit: '£')
end

#calculation_total_income(calculation) ⇒ String

Presents the calculation total income in the correct format

Parameters:

  • calculation (Calculation)

    The calculation to get the total income from

Returns:

  • (String)

    The text to display


92
93
94
# File 'app/helpers/calculation_feedback_helper.rb', line 92

def calculation_total_income(calculation)
  number_to_currency(calculation.inputs[:total_income], precision: 0, unit: '£')
end

#calculator_feedback_for(calculation) ⇒ String

Provides the feedback text for a given calculation. At present, this does use I18n to generate the text, using approximately 10 different keys to form the complete feedback message. It is currently unknown if this will be suitable for different languages (i.e. welsh)

Parameters:

  • calculation (Calculator::Calculation)

    The calculation to display feedback for

Returns:

  • (String)

    The feedback text


9
10
11
12
13
14
15
# File 'app/helpers/calculation_feedback_helper.rb', line 9

def calculator_feedback_for(calculation)
  if calculation.available_help == :none
    should_not_get_help_text(calculation)
  elsif calculation.available_help == :full
    should_get_help_text(calculation) + ' ' + calculator_feedback_explanation(calculation).join(' ')
  end
end

#calculator_form_for(field) ⇒ NilForm, ...

Finds the first form that handles the field given

Parameters:

  • field (String)

    The field to find the form for

Returns:


110
111
112
# File 'app/helpers/calculation_feedback_helper.rb', line 110

def calculator_form_for(field)
  CalculationFormService.for_field(field)
end

#final_calculator_feedback_for(calculation) ⇒ String

Provides the final feedback text for a given calculation.

Parameters:

  • calculation (Calculator::Calculation)

    The calculation to display feedback for

Returns:

  • (String)

    The feedback text


20
21
22
23
24
25
# File 'app/helpers/calculation_feedback_helper.rb', line 20

def final_calculator_feedback_for(calculation)
  marital_status = calculation.inputs[:marital_status]
  t "calculation.feedback.full_remission.decided_by.#{calculation.final_decision_by}.#{marital_status}.detail",
    total_income: calculation_total_income(calculation),
    fee: calculation_fee(calculation)
end

#partial_calculator_feedback_for(calculation) ⇒ String

Provides the final partial feedback text for a given calculation.

Parameters:

  • calculation (Calculator::Calculation)

    The calculation to display feedback for

Returns:

  • (String)

    The feedback text


30
31
32
33
34
35
36
37
# File 'app/helpers/calculation_feedback_helper.rb', line 30

def partial_calculator_feedback_for(calculation)
  marital_status = calculation.inputs[:marital_status]
  t "calculation.feedback.partial_remission.#{marital_status}.detail",
    total_income: calculation_total_income(calculation),
    fee: calculation_fee(calculation),
    remission: calculation_remission(calculation),
    contribution: calculation_contribution(calculation)
end

#should_get_help_text(calculation) ⇒ String

Presents the should get help text in the current language

Parameters:

Returns:

  • (String)

    The text to present


53
54
55
56
57
58
# File 'app/helpers/calculation_feedback_helper.rb', line 53

def should_get_help_text(calculation)
  I18n.t('calculation.feedback.message.positive',
    fee: calculation_fee(calculation),
    disposable_capital: calculation_disposable_capital(calculation),
    subject: I18n.t("calculation.feedback.subject.#{calculation.inputs[:marital_status]}"))
end

#should_not_get_help_text(calculation) ⇒ String

Presents the should not get help text in the current language

Parameters:

Returns:

  • (String)

    The text to present


43
44
45
46
47
# File 'app/helpers/calculation_feedback_helper.rb', line 43

def should_not_get_help_text(calculation)
  I18n.t('calculation.feedback.message.negative',
    fee: calculation_fee(calculation),
    disposable_capital: calculation_disposable_capital(calculation))
end