Class: BenefitsIntake::Metadata
- Inherits:
-
Object
- Object
- BenefitsIntake::Metadata
- Defined in:
- lib/lighthouse/benefits_intake/metadata.rb
Overview
Validate the required metadata which must accompany an upload:
'veteranFirstName': String,
'veteranLastName': String,
'fileNumber': String, # 8-9 digits
'zipCode': String, # 5 or 9 digits
'source': String,
'docType': String,
'businessLine': String, # optional; enum in BUSINESS_LINE
Constant Summary collapse
- BUSINESS_LINE =
{ CMP: 'Compensation requests such as those related to disability, unemployment, and pandemic claims', PMC: 'Pension requests including survivor’s pension', INS: 'Insurance such as life insurance, disability insurance, and other health insurance', EDU: 'Education benefits, programs, and affiliations', VRE: 'Veteran Readiness & Employment such as employment questionnaires, ' \ 'employment discrimination, employment verification', BVA: 'Board of Veteran Appeals', FID: 'Fiduciary / financial appointee, including family member benefits', NCA: 'National Cemetery Administration', OTH: 'Other (this value if used, will be treated as CMP)' }.freeze
Class Method Summary collapse
-
.generate(first_name, last_name, file_number, zip_code, source, doc_type, business_line = nil) ⇒ Object
rubocop:disable Metrics/ParameterLists.
-
.validate(metadata) ⇒ Object
rubocop:enable Metrics/ParameterLists.
- .validate_business_line(metadata) ⇒ Object
- .validate_doc_type(metadata) ⇒ Object
- .validate_file_number(metadata) ⇒ Object
- .validate_first_name(metadata) ⇒ Object
- .validate_last_name(metadata) ⇒ Object
- .validate_nonblank(value, error_label) ⇒ Object
- .validate_presence_and_stringiness(value, error_label) ⇒ Object
- .validate_source(metadata) ⇒ Object
- .validate_zip_code(metadata) ⇒ Object
Class Method Details
.generate(first_name, last_name, file_number, zip_code, source, doc_type, business_line = nil) ⇒ Object
rubocop:disable Metrics/ParameterLists
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lighthouse/benefits_intake/metadata.rb', line 34 def self.generate(first_name, last_name, file_number, zip_code, source, doc_type, business_line = nil) validate({ 'veteranFirstName' => first_name, 'veteranLastName' => last_name, 'fileNumber' => file_number, 'zipCode' => zip_code, 'source' => source, 'docType' => doc_type, 'businessLine' => business_line }) end |
.validate(metadata) ⇒ Object
rubocop:enable Metrics/ParameterLists
47 48 49 50 51 52 53 54 55 |
# File 'lib/lighthouse/benefits_intake/metadata.rb', line 47 def self.validate() validate_first_name() .then { |m| validate_last_name(m) } .then { |m| validate_file_number(m) } .then { |m| validate_zip_code(m) } .then { |m| validate_source(m) } .then { |m| validate_doc_type(m) } .then { |m| validate_business_line(m) } end |
.validate_business_line(metadata) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/lighthouse/benefits_intake/metadata.rb', line 110 def self.validate_business_line() bl = ['businessLine'] if bl bl = bl.dup.to_s.upcase.to_sym bl = :OTH unless BUSINESS_LINE.key?(bl) ['businessLine'] = bl.to_s else .delete('businessLine') end end |
.validate_doc_type(metadata) ⇒ Object
104 105 106 107 108 |
# File 'lib/lighthouse/benefits_intake/metadata.rb', line 104 def self.validate_doc_type() validate_presence_and_stringiness(['docType'], 'doc type') end |
.validate_file_number(metadata) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/lighthouse/benefits_intake/metadata.rb', line 77 def self.validate_file_number() validate_presence_and_stringiness(['fileNumber'], 'file number') unless ['fileNumber'].match?(/^\d{8,9}$/) raise ArgumentError, 'file number is invalid. It must be 8 or 9 digits' end end |
.validate_first_name(metadata) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/lighthouse/benefits_intake/metadata.rb', line 57 def self.validate_first_name() validate_presence_and_stringiness(['veteranFirstName'], 'veteran first name') first_name = I18n.transliterate(['veteranFirstName']).gsub(%r{[^a-zA-Z\-\/\s]}, '').strip.first(50) validate_nonblank(first_name, 'veteran first name') ['veteranFirstName'] = first_name end |
.validate_last_name(metadata) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/lighthouse/benefits_intake/metadata.rb', line 67 def self.validate_last_name() validate_presence_and_stringiness(['veteranLastName'], 'veteran last name') last_name = I18n.transliterate(['veteranLastName']).gsub(%r{[^a-zA-Z\-\/\s]}, '').strip.first(50) validate_nonblank(last_name, 'veteran last name') ['veteranLastName'] = last_name end |
.validate_nonblank(value, error_label) ⇒ Object
128 129 130 |
# File 'lib/lighthouse/benefits_intake/metadata.rb', line 128 def self.validate_nonblank(value, error_label) raise ArgumentError, "#{error_label} is blank" if value.blank? end |
.validate_presence_and_stringiness(value, error_label) ⇒ Object
123 124 125 126 |
# File 'lib/lighthouse/benefits_intake/metadata.rb', line 123 def self.validate_presence_and_stringiness(value, error_label) raise ArgumentError, "#{error_label} is missing" unless value raise ArgumentError, "#{error_label} is not a string" if value.class != String end |
.validate_source(metadata) ⇒ Object
98 99 100 101 102 |
# File 'lib/lighthouse/benefits_intake/metadata.rb', line 98 def self.validate_source() validate_presence_and_stringiness(['source'], 'source') end |
.validate_zip_code(metadata) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/lighthouse/benefits_intake/metadata.rb', line 86 def self.validate_zip_code() validate_presence_and_stringiness(['zipCode'], 'zip code') zip_code = ['zipCode'].dup.gsub(/[^0-9]/, '') zip_code.insert(5, '-') if zip_code.match?(/\A[0-9]{9}\z/) zip_code = '00000' unless zip_code.match?(/\A[0-9]{5}(-[0-9]{4})?\z/) ['zipCode'] = zip_code end |