Repository navigation
Expand file tree
/
Copy pathcalculate_agricultural_holiday_entitlement_flow.rb
More file actions
97 lines (80 loc) · 2.43 KB
/
Copy pathcalculate_agricultural_holiday_entitlement_flow.rb
File metadata and controls
97 lines (80 loc) · 2.43 KB
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
class CalculateAgriculturalHolidayEntitlementFlow < SmartAnswer::Flow
def define
content_id "8834bc7c-7ac7-4d45-8a57-1d5a5dcd70a0"
name "calculate-agricultural-holiday-entitlement"
status :published
radio :work_the_same_number_of_days_each_week? do
option "same-number-of-days"
option "different-number-of-days"
on_response do
self.calculator = SmartAnswer::Calculators::AgriculturalHolidayEntitlementCalculator.new
end
next_node do |response|
case response
when "same-number-of-days"
question :how_many_days_per_week?
when "different-number-of-days"
question :what_date_does_holiday_start?
end
end
end
radio :how_many_days_per_week? do
option "7-days"
option "6-days"
option "5-days"
option "4-days"
option "3-days"
option "2-days"
option "1-day"
on_response do |response|
# XXX: this is a bit nasty and takes advantage of the fact that
# to_i only looks for the very first integer
calculator.days_worked_per_week = response.to_i
end
next_node do
question :worked_for_same_employer?
end
end
date_question :what_date_does_holiday_start? do
on_response do |response|
calculator.holiday_starts_on = response
end
next_node do
question :how_many_total_days?
end
end
radio :worked_for_same_employer? do
option "same-employer"
option "multiple-employers"
next_node do |response|
case response
when "same-employer"
outcome :done
when "multiple-employers"
question :how_many_weeks_at_current_employer?
end
end
end
value_question :how_many_total_days?, parse: Integer do
on_response do |response|
calculator.total_days_worked = response
end
validate { calculator.valid_total_days_worked? }
next_node do
question :worked_for_same_employer?
end
end
value_question :how_many_weeks_at_current_employer?, parse: Integer do
# Has to be less than a full year
validate { calculator.valid_weeks_at_current_employer? }
on_response do |response|
calculator.weeks_at_current_employer = response
end
next_node do
outcome :done_with_number_formatting
end
end
outcome :done
outcome :done_with_number_formatting
end
end