Module: PdfFill::Forms::FormHelper
- Included in:
- CommonPtsd, Va210538, Va214142, Va21674, Va218940, Va21p530, Va21p530v2, Va261880, Va281900, Va288832, Va686c674
- Defined in:
- lib/pdf_fill/forms/form_helper.rb
Defined Under Namespace
Modules: PhoneNumberFormatting
Instance Method Summary
collapse
Instance Method Details
#address_block(address) ⇒ Object
96
97
98
99
100
101
102
103
104
|
# File 'lib/pdf_fill/forms/form_helper.rb', line 96
def address_block(address)
return if address.nil?
[
[address['street'], address['street2']].compact.join(' '),
[address['city'], address['state'], address['postalCode']].compact.join(' '),
address['country']
].compact.join("\n")
end
|
#combine_date_ranges(date_range_array) ⇒ Object
90
91
92
93
94
|
# File 'lib/pdf_fill/forms/form_helper.rb', line 90
def combine_date_ranges(date_range_array)
return if date_range_array.nil?
date_range_array.map { |r| "from: #{r['from']} to: #{r['to']}" if r }.join("\n")
end
|
#expand_checkbox_as_hash(hash, key) ⇒ Object
106
107
108
109
110
111
112
113
114
|
# File 'lib/pdf_fill/forms/form_helper.rb', line 106
def expand_checkbox_as_hash(hash, key)
value = hash.try(:[], key)
return if value.blank?
hash['checkbox'] = {
value => true
}
end
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/pdf_fill/forms/form_helper.rb', line 27
def (address)
return if address.blank?
country = address['country'] || address['country_name']
return if country.blank?
if country.size == 3
IsoCountryCodes.find(country).alpha2
else
IsoCountryCodes.search_by_name(country)[0].alpha2
end
rescue IsoCountryCodes::UnknownCodeError
country
end
|
18
19
20
21
22
23
24
25
|
# File 'lib/pdf_fill/forms/form_helper.rb', line 18
def (hash, key)
full_name = hash[key]
return if full_name.blank?
middle_name = full_name['middle']
full_name['middleInitial'] = middle_name[0] if middle_name.present?
full_name
end
|
124
125
126
127
128
|
# File 'lib/pdf_fill/forms/form_helper.rb', line 124
def format_boolean(bool_attribute)
return '' if bool_attribute.nil?
bool_attribute ? 'Yes' : 'No'
end
|
#select_checkbox(value) ⇒ Object
120
121
122
|
# File 'lib/pdf_fill/forms/form_helper.rb', line 120
def select_checkbox(value)
value ? 1 : 'Off'
end
|
116
117
118
|
# File 'lib/pdf_fill/forms/form_helper.rb', line 116
def select_radio_button(value)
value ? 0 : 'Off'
end
|
#split_date(date) ⇒ Object
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/pdf_fill/forms/form_helper.rb', line 79
def split_date(date)
return unless validate_date(date)
s_date = date.split('-')
{
'month' => s_date[1],
'day' => s_date.last,
'year' => s_date.first
}
end
|
#split_postal_code(address) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/pdf_fill/forms/form_helper.rb', line 42
def split_postal_code(address)
return if address.blank?
postal_code = address['postalCode'] || address['zip_code']
return if postal_code.blank?
postal_code = postal_code.tr('\-', '')
split_postal_code = postal_code.scan(/.{1,5}/)
if split_postal_code.length == 2
{
'firstFive' => split_postal_code.first,
'lastFour' => split_postal_code.last
}
else
{
'firstFive' => split_postal_code.first,
'lastFour' => ''
}
end
end
|
#split_ssn(veteran_social_security_number) ⇒ Object
8
9
10
11
12
13
14
15
16
|
# File 'lib/pdf_fill/forms/form_helper.rb', line 8
def split_ssn(veteran_social_security_number)
return if veteran_social_security_number.blank?
{
'first' => veteran_social_security_number[0..2],
'second' => veteran_social_security_number[3..4],
'third' => veteran_social_security_number[5..8]
}
end
|
#validate_date(date) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/pdf_fill/forms/form_helper.rb', line 65
def validate_date(date)
return if date.blank?
format_ok = date.match(/\d{4}-\d{2}-\d{2}/)
begin
parseable = Date.strptime(date, '%Y-%m-%d')
rescue ArgumentError
false
end
format_ok && parseable
end
|