Class: IdCardAttributes

Inherits:
Object
  • Object
show all
Defined in:
app/models/id_card_attributes.rb

Constant Summary collapse

SERVICE_KEYS =

Mapping from VA Profile branch of service keys to value expected by VIC

{
  'F' => 'AF',   # Air Force
  'A' => 'ARMY', # Army
  'C' => 'CG',   # Coast Guard
  'M' => 'MC',   # Marine Corps
  'N' => 'NAVY', # Navy
  'O' => 'NOAA', # NOAA
  'H' => 'PHS'   # USPHS
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#userObject

Returns the value of attribute user.



4
5
6
# File 'app/models/id_card_attributes.rb', line 4

def user
  @user
end

Class Method Details

.for_user(user) ⇒ Object



6
7
8
9
10
# File 'app/models/id_card_attributes.rb', line 6

def self.for_user(user)
  id_attributes = IdCardAttributes.new
  id_attributes.user = user
  id_attributes
end

Instance Method Details

#branches_of_serviceObject (private)



49
50
51
52
53
54
# File 'app/models/id_card_attributes.rb', line 49

def branches_of_service
  branches = military_info.service_episodes_by_date.map do |ep|
    SERVICE_KEYS[ep.branch_of_service_code]
  end
  branches.compact.join(',')
end

#discharge_typesObject (private)



56
57
58
59
60
61
62
63
64
# File 'app/models/id_card_attributes.rb', line 56

def discharge_types
  ## If the discharge code is one of the known, unwanted three-character
  ##  codes from VA Profile, replace it with nil.
  invalid_codes = %w[DVN DVU CVI VNA]
  all_codes = military_info.service_episodes_by_date.map(&:character_of_discharge_code)
  discharges = all_codes.map { |code| invalid_codes.include?(code) ? nil : code }
  # Remove nil values and convert array of codes to a string
  discharges.compact.join(',')
end

#military_infoObject (private)



66
67
68
# File 'app/models/id_card_attributes.rb', line 66

def military_info
  @military_info ||= VAProfile::Prefill::MilitaryInformation.new(user)
end

#title38_status_codeObject (private)



43
44
45
46
47
# File 'app/models/id_card_attributes.rb', line 43

def title38_status_code
  @user.veteran_status.title38_status || 'UNKNOWN'
rescue
  'UNKNOWN'
end

#traitsObject

Return dict of traits in canonical order



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/id_card_attributes.rb', line 13

def traits
  {
    'edipi' => @user.edipi,
    'firstname' => @user.first_name,
    'lastname' => @user.last_name,
    'address' => @user.address[:street] || '',
    'city' => @user.address[:city] || '',
    'state' => @user.address[:state] || '',
    'zip' => @user.address[:postal_code] || '',
    'email' => @user.email || '',
    'phone' => @user.home_phone || '',
    'title38status' => title38_status_code,
    'branchofservice' => branches_of_service,
    'dischargetype' => discharge_types
  }
end