Class: BGS::Job

Inherits:
Object
  • Object
show all
Includes:
Utilities::Helpers
Defined in:
app/sidekiq/bgs/job.rb

Instance Method Summary collapse

Methods included from Utilities::Helpers

#normalize_composite_characters, #remove_special_characters_from_name

Instance Method Details

#in_progress_form_copy(in_progress_form) ⇒ Object



9
10
11
12
13
14
15
# File 'app/sidekiq/bgs/job.rb', line 9

def in_progress_form_copy(in_progress_form)
  return nil if in_progress_form.blank?

  OpenStruct.new(meta_data: in_progress_form.,
                 form_data: in_progress_form.form_data,
                 user_account: in_progress_form.)
end

#normalize_names_and_addresses!(hash) ⇒ Object

BGS doesn’t accept name and address_line fields with non-ASCII characters (e.g. ü, ñ), and doesn’t accept names with apostrophes. This method recursively iterates through a given hash and strips unprocessable characters from name and address_line fields. The method is called in ‘SubmitForm686cJob` and `SubmitForm674Job` with an enormous form payload potentially containing many names and addresses. See `spec/factories/686c/form_686c_674.rb` for an example of such a payload.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/sidekiq/bgs/job.rb', line 30

def normalize_names_and_addresses!(hash)
  hash.each do |key, val|
    case val
    when Hash
      normalize_names_and_addresses!(val)
    when Array
      val.each { |v| normalize_names_and_addresses!(v) if v.is_a?(Hash) }
    else
      is_name_key = %w[first middle last].include?(key)
      if val && (is_name_key || key.include?('address_line'))
        val = normalize_composite_characters(val)
        val = remove_special_characters_from_name(val) if is_name_key
        hash[key] = val
      end
    end
  end
end

#salvage_save_in_progress_form(form_id, user_uuid, copy) ⇒ Object



17
18
19
20
21
22
23
# File 'app/sidekiq/bgs/job.rb', line 17

def salvage_save_in_progress_form(form_id, user_uuid, copy)
  return if copy.blank?

  form = InProgressForm.where(form_id:, user_uuid:).first_or_initialize
  form. = copy.
  form.update(form_data: copy.form_data)
end