-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathoverseas_passports_calculator.rb
191 lines (150 loc) · 5.01 KB
/
overseas_passports_calculator.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
181
182
183
184
185
186
187
188
189
190
191
module SmartAnswer::Calculators
class OverseasPassportsCalculator
APPLY_IN_NEIGHBOURING_COUNTRIES = %w(
british-indian-ocean-territory north-korea south-georgia-and-south-sandwich-islands
)
BOOK_APPOINTMENT_ONLINE_COUNTRIES = %w(
kyrgyzstan tajikistan turkmenistan uzbekistan
)
UK_VISA_APPLICATION_CENTRE_COUNTRIES = %w(
afghanistan algeria azerbaijan bangladesh belarus burundi burma cambodia
china gaza georgia india indonesia kazakhstan kyrgyzstan laos lebanon
mauritania morocco nepal pakistan russia tajikistan thailand turkmenistan
ukraine uzbekistan western-sahara vietnam venezuela
)
UK_VISA_APPLICATION_WITH_COLOUR_PICTURES_COUNTRIES = %w(
afghanistan azerbaijan algeria bangladesh belarus burma cambodia china
georgia india indonesia kazakhstan laos lebanon mauritania morocco nepal
pakistan tajikistan thailand turkmenistan ukraine uzbekistan russia
vietnam venezuela western-sahara
)
EXCLUDE_COUNTRIES = %w(
holy-see british-antarctic-territory
)
INELIGIBLE_COUNTRIES = %w(
iran libya syria yemen
)
IPS_APPLICATION_TYPES = %w(
ips_application_1
ips_application_2
ips_application_3
)
NON_UK_VISA_APPLICATION_WITH_COLOUR_PICTURES_COUNTRIES = %w(
burma cuba sudan tajikistan turkmenistan uzbekistan
)
attr_accessor :current_location
attr_accessor :birth_location
attr_accessor :application_action
attr_accessor :child_or_adult
def initialize(data_query: nil)
@data_query = data_query || PassportAndEmbassyDataQuery.new
end
def book_appointment_online?
BOOK_APPOINTMENT_ONLINE_COUNTRIES.include?(current_location)
end
def uk_visa_application_centre?
UK_VISA_APPLICATION_CENTRE_COUNTRIES.include?(current_location)
end
def uk_visa_application_with_colour_pictures?
UK_VISA_APPLICATION_WITH_COLOUR_PICTURES_COUNTRIES.include?(current_location)
end
def non_uk_visa_application_with_colour_pictures?
NON_UK_VISA_APPLICATION_WITH_COLOUR_PICTURES_COUNTRIES.include?(current_location)
end
def ineligible_country?
INELIGIBLE_COUNTRIES.include?(current_location)
end
def apply_in_neighbouring_countries?
APPLY_IN_NEIGHBOURING_COUNTRIES.include?(current_location)
end
def alternate_embassy_location(location = current_location)
PassportAndEmbassyDataQuery::ALT_EMBASSIES[location]
end
def world_location(location = current_location)
search_location = alternate_embassy_location(location) || location
WorldLocation.find(search_location)
end
def world_location_name(location = current_location)
world_location(location).name
end
def fco_organisation(location = current_location)
world_location(location).fco_organisation
end
def cash_only_country?
@data_query.cash_only_countries?(current_location)
end
def renewing_country?
@data_query.renewing_countries?(current_location)
end
def renewing_new?
application_action == 'renewing_new'
end
def renewing_old?
application_action == 'renewing_old'
end
def applying?
application_action == 'applying'
end
def replacing?
application_action == 'replacing'
end
def overseas_passports_embassies(location = current_location)
organisation = fco_organisation(location)
organisation ? organisation.offices_with_service('Overseas Passports Service') : []
end
def general_action
application_action =~ /^renewing_/ ? 'renewing' : application_action
end
def passport_data(location = current_location)
@data_query.find_passport_data(location)
end
def application_type
data = passport_data
data ? data['type'] : nil
end
def application_form
data = passport_data
data ? data['app_form'] : nil
end
def application_group(location)
data = passport_data(location)
data ? data['group'] : nil
end
def optimistic_processing_time
data = passport_data
data ? data['optimistic_processing_time?'] : nil # pretty weird hash key
end
def application_address
data = passport_data
data ? data['address'] : nil
end
def waiting_time
data = passport_data
data ? data[application_action] : nil
end
def supporting_documents
if birth_location.blank? || birth_location == 'united_kingdom'
application_group(current_location)
else
application_group(birth_location)
end
end
def ips_application?
IPS_APPLICATION_TYPES.include?(application_type)
end
def ips_online_application?
data = passport_data
data && data['online_application']
end
def application_office?
data = passport_data
data && data['application_office']
end
def ips_number
application_type.split("_")[2] if ips_application?
end
def ips_docs_number
supporting_documents.split("_")[3] if ips_application?
end
end
end