-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathstate-pension-through-partner.rb
180 lines (157 loc) · 5.87 KB
/
state-pension-through-partner.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
module SmartAnswer
class StatePensionThroughPartnerFlow < Flow
def define
content_id "42a41808-b338-4e4b-a703-47195982f4c8"
name 'state-pension-through-partner'
status :published
satisfies_need "100578"
### This will need updating before 6th April 2016 ###
# Q1
multiple_choice :what_is_your_marital_status? do
option :married
option :will_marry_before_specific_date
option :will_marry_on_or_after_specific_date
option :widowed
option :divorced
save_input_as :marital_status
calculate :answers do |response|
answers = []
if response == "married" or response == "will_marry_before_specific_date"
answers << :old1
elsif response == "will_marry_on_or_after_specific_date"
answers << :new1
elsif response == "widowed"
answers << :widow
end
answers
end
calculate :lower_basic_state_pension_rate do
rate = SmartAnswer::Calculators::RatesQuery.new('state_pension').rates.lower_weekly_rate
"£#{rate}"
end
calculate :higher_basic_state_pension_rate do
rate = SmartAnswer::Calculators::RatesQuery.new('state_pension').rates.weekly_rate
"£#{rate}"
end
permitted_next_nodes = [
:what_is_your_gender?,
:when_will_you_reach_pension_age?
]
next_node(permitted: permitted_next_nodes) do |response|
if response == 'divorced'
:what_is_your_gender?
else
:when_will_you_reach_pension_age?
end
end
end
# Q2
multiple_choice :when_will_you_reach_pension_age? do
option :your_pension_age_before_specific_date
option :your_pension_age_after_specific_date
save_input_as :when_will_you_reach_pension_age
calculate :answers do |response|
if response == "your_pension_age_before_specific_date"
answers << :old2
elsif response == "your_pension_age_after_specific_date"
answers << :new2
end
answers << :old3 if marital_status == "widowed"
answers
end
next_node_calculation(:widow_and_new_pension) do |response|
answers == [:widow] && response == "your_pension_age_after_specific_date"
end
next_node_calculation(:widow_and_old_pension) do |response|
answers == [:widow] && response == "your_pension_age_before_specific_date"
end
permitted_next_nodes = [
:what_is_your_gender?,
:when_will_your_partner_reach_pension_age?,
:widow_and_old_pension_outcome
]
next_node(permitted: permitted_next_nodes) do
if widow_and_new_pension
:what_is_your_gender?
elsif widow_and_old_pension
:widow_and_old_pension_outcome
else
:when_will_your_partner_reach_pension_age?
end
end
end
#Q3
multiple_choice :when_will_your_partner_reach_pension_age? do
option :partner_pension_age_before_specific_date
option :partner_pension_age_after_specific_date
next_node_calculation :answers do |response|
if response == "partner_pension_age_before_specific_date"
answers << :old3
elsif response == "partner_pension_age_after_specific_date"
answers << :new3
end
answers
end
next_node_calculation(:current_rules_no_additional_pension) {
answers == [:old1, :old2, :old3] || answers == [:new1, :old2, :old3]
}
next_node_calculation(:current_rules_national_insurance_no_state_pension) {
answers == [:old1, :old2, :new3] || answers == [:new1, :old2, :new3]
}
permitted_next_nodes = [
:current_rules_national_insurance_no_state_pension_outcome,
:current_rules_no_additional_pension_outcome,
:what_is_your_gender?
]
next_node(permitted: permitted_next_nodes) do
if current_rules_no_additional_pension
:current_rules_no_additional_pension_outcome
elsif current_rules_national_insurance_no_state_pension
:current_rules_national_insurance_no_state_pension_outcome
else
:what_is_your_gender?
end
end
end
# Q4
multiple_choice :what_is_your_gender? do
option :male_gender
option :female_gender
save_input_as :gender
permitted_next_nodes = [
:age_dependent_pension_outcome,
:impossibility_due_to_divorce_outcome,
:impossibility_to_increase_pension_outcome,
:married_woman_and_state_pension_outcome,
:married_woman_no_state_pension_outcome
]
next_node(permitted: permitted_next_nodes) do |response|
case response
when 'male_gender'
if marital_status == 'divorced'
:impossibility_due_to_divorce_outcome
else
:impossibility_to_increase_pension_outcome
end
when 'female_gender'
if marital_status == 'divorced'
:age_dependent_pension_outcome
elsif marital_status == 'widowed'
:married_woman_and_state_pension_outcome
else
:married_woman_no_state_pension_outcome
end
end
end
end
outcome :widow_and_old_pension_outcome
outcome :current_rules_no_additional_pension_outcome
outcome :current_rules_national_insurance_no_state_pension_outcome
outcome :impossibility_due_to_divorce_outcome
outcome :impossibility_to_increase_pension_outcome
outcome :age_dependent_pension_outcome
outcome :married_woman_and_state_pension_outcome
outcome :married_woman_no_state_pension_outcome
end
end
end