Class: EducationForm::Forms::Base

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TextHelper
Defined in:
app/sidekiq/education_form/forms/base.rb

Direct Known Subclasses

VA0993, VA0994, VA10203, VA1990, VA1990e, VA1990n, VA1990s, VA1995, VA5490, VA5495

Constant Summary collapse

TEMPLATE_PATH =
Rails.root.join('app', 'sidekiq', 'education_form', 'templates')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Base

Returns a new instance of Base.



57
58
59
60
61
# File 'app/sidekiq/education_form/forms/base.rb', line 57

def initialize(app)
  @record = app
  @form = app.open_struct_form
  @text = format unless instance_of?(Base)
end

Instance Attribute Details

#formObject

Returns the value of attribute form.



10
11
12
# File 'app/sidekiq/education_form/forms/base.rb', line 10

def form
  @form
end

#recordObject

Returns the value of attribute record.



10
11
12
# File 'app/sidekiq/education_form/forms/base.rb', line 10

def record
  @record
end

#textObject

Returns the value of attribute text.



10
11
12
# File 'app/sidekiq/education_form/forms/base.rb', line 10

def text
  @text
end

Class Method Details

.build(app) ⇒ Object



12
13
14
15
# File 'app/sidekiq/education_form/forms/base.rb', line 12

def self.build(app)
  klass = "EducationForm::Forms::VA#{app.form_type}".constantize
  klass.new(app)
end

Instance Method Details

#applicant_nameObject



49
50
51
# File 'app/sidekiq/education_form/forms/base.rb', line 49

def applicant_name
  @applicant.veteranFullName
end

#applicant_ssnObject



53
54
55
# File 'app/sidekiq/education_form/forms/base.rb', line 53

def applicant_ssn
  @applicant.veteranSocialSecurityNumber
end

#benefit_type(application) ⇒ Object



31
32
33
# File 'app/sidekiq/education_form/forms/base.rb', line 31

def benefit_type(application)
  application.benefit&.gsub('chapter', 'CH')
end

#direct_deposit_type(type) ⇒ Object



17
18
19
20
# File 'app/sidekiq/education_form/forms/base.rb', line 17

def direct_deposit_type(type)
  dd_types = { 'STARTUPDATE' => 'Start or Update', 'STOP' => 'Stop', 'NOCHANGE' => 'Do Not Change' }
  dd_types[type&.upcase]
end

#disclosure_for(type) ⇒ Object



35
36
37
38
39
# File 'app/sidekiq/education_form/forms/base.rb', line 35

def disclosure_for(type)
  return if type.blank?

  "#{parse_with_template_path("1990-disclosure/_#{type}")}\n"
end

#employment_history(job_history, post_military: nil) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
# File 'app/sidekiq/education_form/forms/base.rb', line 183

def employment_history(job_history, post_military: nil)
  wrapped_list = Array(job_history)
  wrapped_list = wrapped_list.select { |job| job.postMilitaryJob == post_military } unless post_military.nil?
  # we need at least one record to be in the form.
  wrapped_list << OpenStruct.new if wrapped_list.empty?
  wrapped_list.map do |job|
    "        Principal Occupation: #{job.name}
    Number of Months: #{job.months}
    License or Rating: #{job.licenseOrRating}"
  end.join("\n\n")
end

#formatObject

Note:

The input fixtures in {spec/fixtures/education_benefits_claims/*/.json contain Windows-1252 encoding “double right-single-quotation-mark”, (’) Unicode %u2019 but .spl file (expected output) contains ASCII apostrophe (‘), code %27.

Workaround is to sub the ASCII apostrophe, though other non-UTF-8 chars might break specs

Convert the JSON/OStruct document into the text format that we submit to the backend



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/sidekiq/education_form/forms/base.rb', line 71

def format
  @applicant = @form
  # the spool file has a requirement that lines be 80 bytes (not characters), and since they
  # use windows-style newlines, that leaves us with a width of 78
  wrapped = word_wrap(parse_with_template_path(@record.form_type), line_width: 78)
  wrapped = wrapped.gsub(/’|‘/, "'").gsub(/”|“/, '"')
  # We can only send ASCII, so make a best-effort at that.
  transliterated = ActiveSupport::Inflector.transliterate(wrapped, locale: :en)
  # Trim any lines that end in whitespace, but keep the lines themselves
  transliterated.gsub!(/ +\n/, "\n")
  # The spool file must actually use windows style linebreaks
  transliterated.gsub("\n", EducationForm::CreateDailySpoolFiles::WINDOWS_NOTEPAD_LINEBREAK)
end

#full_address(address, indent: false) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
# File 'app/sidekiq/education_form/forms/base.rb', line 148

def full_address(address, indent: false)
  return '' if address.nil?

  seperator = indent ? "\n        " : "\n"
  [
    address.street,
    address.street2,
    [address.city, address.state, address.postalCode].compact.join(', '),
    address.country
  ].compact.join(seperator).upcase
end

#full_address_with_street3(address, indent: false) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
# File 'app/sidekiq/education_form/forms/base.rb', line 160

def full_address_with_street3(address, indent: false)
  return '' if address.nil?

  seperator = indent ? "\n        " : "\n"
  [
    address.street,
    address.street2,
    address.street3,
    [address.city, address.state, address.postalCode].compact.join(', '),
    address.country
  ].compact.join(seperator).upcase
end

#full_name(name) ⇒ Object



129
130
131
132
133
# File 'app/sidekiq/education_form/forms/base.rb', line 129

def full_name(name)
  return '' if name.nil?

  [name.first, name.middle, name.last, name&.suffix].compact.join(' ')
end

#get_template(filename) ⇒ Object



101
102
103
# File 'app/sidekiq/education_form/forms/base.rb', line 101

def get_template(filename)
  File.read(File.join(TEMPLATE_PATH, "#{filename}.erb"))
end

#headerObject



97
98
99
# File 'app/sidekiq/education_form/forms/base.rb', line 97

def header
  parse_with_template_path('header')
end

#header_form_typeObject



41
42
43
# File 'app/sidekiq/education_form/forms/base.rb', line 41

def header_form_type
  "V#{@record.form_type}"
end

#hours_and_type(training) ⇒ Object



173
174
175
176
177
178
179
180
181
# File 'app/sidekiq/education_form/forms/base.rb', line 173

def hours_and_type(training)
  return_val = training&.hours&.to_s
  return '' if return_val.blank?

  hours_type = training&.hoursType
  return_val += " (#{hours_type})" if hours_type.present?

  return_val
end

#parse_with_template(template) ⇒ Object



85
86
87
88
89
90
91
# File 'app/sidekiq/education_form/forms/base.rb', line 85

def parse_with_template(template)
  # Because our template files end in newlines, we have to
  # chomp off the final rendered line to get the correct
  # output. Any intentionally blank lines before the final
  # one will remain.
  ERB.new(template, trim_mode: '-').result(binding).chomp
end

#parse_with_template_path(path) ⇒ Object



93
94
95
# File 'app/sidekiq/education_form/forms/base.rb', line 93

def parse_with_template_path(path)
  parse_with_template(get_template(path))
end

#schoolObject



45
46
47
# File 'app/sidekiq/education_form/forms/base.rb', line 45

def school
  @applicant.school
end

#school_nameObject



135
136
137
# File 'app/sidekiq/education_form/forms/base.rb', line 135

def school_name
  school&.name&.upcase&.strip
end

#school_name_and_addr(school) ⇒ Object



139
140
141
142
143
144
145
146
# File 'app/sidekiq/education_form/forms/base.rb', line 139

def school_name_and_addr(school)
  return '' if school.nil?

  [
    school.name,
    full_address(school.address)
  ].compact.join("\n")
end

#ssn_gender_dob(veteran = true) ⇒ Object



22
23
24
25
26
27
28
29
# File 'app/sidekiq/education_form/forms/base.rb', line 22

def ssn_gender_dob(veteran = true)
  prefix = veteran ? 'veteran' : 'relative'
  ssn = @applicant.public_send("#{prefix}SocialSecurityNumber")
  gender = @applicant.gender
  dob = @applicant.public_send("#{prefix}DateOfBirth")

  "SSN: #{ssn}         Sex: #{gender}             Date of Birth: #{dob}"
end

#to_date(date) ⇒ Object

is this needed? will it the data come in the correct format? better to have the helper..



125
126
127
# File 'app/sidekiq/education_form/forms/base.rb', line 125

def to_date(date)
  date || (' ' * 10) # '00/00/0000'.length
end

#value_or_na(value) ⇒ Object



120
121
122
# File 'app/sidekiq/education_form/forms/base.rb', line 120

def value_or_na(value)
  value.nil? ? 'N/A' : value
end

#yesno(bool) ⇒ Object

N/A is used for “the user wasn’t shown this option”, which is distinct from Y/N.



108
109
110
111
112
# File 'app/sidekiq/education_form/forms/base.rb', line 108

def yesno(bool)
  return 'N/A' if bool.nil?

  bool ? 'YES' : 'NO'
end

#yesno_or_blank(bool) ⇒ Object



114
115
116
117
118
# File 'app/sidekiq/education_form/forms/base.rb', line 114

def yesno_or_blank(bool)
  return '' if bool.nil?

  bool ? 'YES' : 'NO'
end