Class: PdfFill::Forms::FormBase
- Inherits:
-
Object
- Object
- PdfFill::Forms::FormBase
show all
- Defined in:
- lib/pdf_fill/forms/form_base.rb
Direct Known Subclasses
Va1010cg, Va210538, Va210781, Va210781a, Va214142, Va21674, Va218940, Va21p0969, Va21p530, Va21p530v2, Va261880, Va281900, Va288832, Va5655, Va686c674
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#combine_both_addr(hash, key) ⇒ Object
-
#combine_full_address(address) ⇒ Object
-
#combine_full_address_extras(address) ⇒ Object
-
#combine_full_name(full_name) ⇒ Object
-
#combine_hash(hash, keys, separator = ' ') ⇒ Object
-
#combine_name_addr(hash, address_key: 'address', name_key: 'name', combined_key: 'nameAndAddr') ⇒ Object
-
#combine_name_addr_extras(hash, name_key, address_key) ⇒ Object
-
#combine_postal_code(postal_code) ⇒ Object
-
#combine_previous_names(previous_names) ⇒ Object
-
#expand_checkbox(value, key) ⇒ Object
-
#expand_date_range(hash, key) ⇒ Object
-
#expand_signature(full_name, signature_date = Time.zone.today) ⇒ Object
-
#initialize(form_data) ⇒ FormBase
constructor
A new instance of FormBase.
Constructor Details
#initialize(form_data) ⇒ FormBase
Returns a new instance of FormBase.
14
15
16
|
# File 'lib/pdf_fill/forms/form_base.rb', line 14
def initialize(form_data)
@form_data = form_data.deep_dup
end
|
Instance Attribute Details
Returns the value of attribute form_data.
8
9
10
|
# File 'lib/pdf_fill/forms/form_base.rb', line 8
def form_data
@form_data
end
|
Class Method Details
.date_strftime ⇒ Object
10
11
12
|
# File 'lib/pdf_fill/forms/form_base.rb', line 10
def self.date_strftime
'%m/%d/%Y'
end
|
Instance Method Details
#combine_both_addr(hash, key) ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/pdf_fill/forms/form_base.rb', line 41
def combine_both_addr(hash, key)
original_addr = hash[key]
return if original_addr.blank?
= (original_addr)
address = combine_full_address(original_addr)
hash[key] = PdfFill::FormValue.new(address, )
end
|
#combine_full_address(address) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/pdf_fill/forms/form_base.rb', line 80
def combine_full_address(address)
combine_hash(
address,
%w[
street
street2
city
state
postalCode
country
],
', '
)
end
|
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/pdf_fill/forms/form_base.rb', line 59
def (address)
return if address.blank?
postal_code = address['postalCode']
postal_code = combine_postal_code(postal_code) if postal_code.is_a?(Hash)
[
address['street'],
address['street2'],
[address['city'], address['state'], postal_code].compact.join(', '),
address['country']
].compact.join("\n")
end
|
#combine_full_name(full_name) ⇒ Object
101
102
103
|
# File 'lib/pdf_fill/forms/form_base.rb', line 101
def combine_full_name(full_name)
combine_hash(full_name, %w[first middle last suffix])
end
|
#combine_hash(hash, keys, separator = ' ') ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/pdf_fill/forms/form_base.rb', line 112
def combine_hash(hash, keys, separator = ' ')
return if hash.blank?
combined = []
keys.each do |key|
combined << hash[key]
end
combined.compact.join(separator)
end
|
#combine_name_addr(hash, address_key: 'address', name_key: 'name', combined_key: 'nameAndAddr') ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/pdf_fill/forms/form_base.rb', line 22
def combine_name_addr(hash, address_key: 'address', name_key: 'name', combined_key: 'nameAndAddr')
return if hash.try(:[], address_key).blank?
= (hash, name_key, address_key)
hash['combinedAddr'] = if hash[address_key]['postalCode'].is_a?(Hash)
address_dup = hash[address_key].deep_dup
address_dup['postalCode'] = combine_postal_code(address_dup['postalCode'])
combine_full_address(address_dup)
else
combine_full_address(hash[address_key])
end
address = combine_hash(hash, [name_key, 'combinedAddr'], ', ')
hash.delete('combinedAddr')
hash[combined_key] = PdfFill::FormValue.new(address, )
end
|
18
19
20
|
# File 'lib/pdf_fill/forms/form_base.rb', line 18
def (hash, name_key, address_key)
[hash[name_key], (hash[address_key])].compact.join("\n")
end
|
#combine_postal_code(postal_code) ⇒ Object
73
74
75
76
77
78
|
# File 'lib/pdf_fill/forms/form_base.rb', line 73
def combine_postal_code(postal_code)
code = postal_code.deep_dup
combined_postal_code = code['firstFive'].to_s
combined_postal_code << "-#{code['lastFour']}" unless code['lastFour'].nil?
combined_postal_code
end
|
#combine_previous_names(previous_names) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/pdf_fill/forms/form_base.rb', line 51
def combine_previous_names(previous_names)
return if previous_names.blank?
previous_names.map do |previous_name|
combine_full_name(previous_name)
end.join(', ')
end
|
#expand_checkbox(value, key) ⇒ Object
105
106
107
108
109
110
|
# File 'lib/pdf_fill/forms/form_base.rb', line 105
def expand_checkbox(value, key)
{
"has#{key}" => value == true,
"no#{key}" => value == false
}
end
|
#expand_date_range(hash, key) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/pdf_fill/forms/form_base.rb', line 124
def expand_date_range(hash, key)
return if hash.blank?
date_range = hash[key]
return if date_range.blank?
hash["#{key}Start"] = date_range['from']
hash["#{key}End"] = date_range['to']
hash.delete(key)
hash
end
|
#expand_signature(full_name, signature_date = Time.zone.today) ⇒ Object
95
96
97
98
99
|
# File 'lib/pdf_fill/forms/form_base.rb', line 95
def expand_signature(full_name, signature_date = Time.zone.today)
signature = combine_hash(full_name, %w[first last])
@form_data['signature'] = signature
@form_data['signatureDate'] = signature_date.to_s if signature.present?
end
|