Class: HCA::MilitaryInformation

Inherits:
Object
  • Object
show all
Defined in:
lib/hca/military_information.rb

Constant Summary collapse

PREFILL_METHODS =
%w[
  hca_last_service_branch
  last_entry_date
  last_discharge_date
  discharge_type
  post_nov111998_combat
  sw_asia_combat
].freeze
HCA_SERVICE_BRANCHES =
{
  'A' => 'army',
  'C' => 'coast guard',
  'F' => 'air force',
  'H' => 'usphs',
  'M' => 'marine corps',
  'N' => 'navy',
  'O' => 'noaa'
}.freeze
DISCHARGE_TYPES =
{
  'A' => 'honorable',
  'B' => 'general',
  'D' => 'bad-conduct',
  'F' => 'dishonorable',
  'J' => 'honorable',
  'K' => 'dishonorable'
}.freeze
SOUTHWEST_ASIA =
%w[
  AM
  AZ
  BH
  CY
  GE
  IQ
  IL
  JO
  KW
  LB
  OM
  QA
  SA
  SY
  TR
  AE
  YE
].freeze
NOV_1998 =
Date.new(1998, 11, 11)
GULF_WAR_RANGE =
(Date.new(1990, 8, 2)..NOV_1998)

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ MilitaryInformation

Returns a new instance of MilitaryInformation.



58
59
60
# File 'lib/hca/military_information.rb', line 58

def initialize(user)
  @service = VAProfile::MilitaryPersonnel::Service.new(user)
end

Instance Method Details

#deployed_to?(countries, date_range) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/hca/military_information.rb', line 90

def deployed_to?(countries, date_range)
  deployments.each do |deployment|
    next if deployment['deployment_locations'].nil? # Skip if deployment_locations is nil

    deployment['deployment_locations'].each do |location|
      location_date_range = location['deployment_location_begin_date']..location['deployment_location_end_date']

      if countries.include?(location['deployment_country_code']) && date_range.overlaps?(location_date_range)
        return true
      end
    end
  end

  false
end

#deploymentsObject



128
129
130
131
132
133
134
135
136
137
138
# File 'lib/hca/military_information.rb', line 128

def deployments
  @deployments ||= lambda do
    return_val = []

    service_history.episodes.each do |episode|
      return_val += episode.deployments if episode.deployments.present?
    end

    return_val
  end.call
end

#discharge_typeObject



114
115
116
117
118
# File 'lib/hca/military_information.rb', line 114

def discharge_type
  return if latest_service_episode.blank?

  DISCHARGE_TYPES[latest_service_episode&.character_of_discharge_code]
end

#hca_last_service_branchObject



72
73
74
# File 'lib/hca/military_information.rb', line 72

def hca_last_service_branch
  HCA_SERVICE_BRANCHES[latest_service_episode&.branch_of_service_code] || 'other'
end

#last_discharge_dateObject



120
121
122
# File 'lib/hca/military_information.rb', line 120

def last_discharge_date
  latest_service_episode&.end_date
end

#last_entry_dateObject



124
125
126
# File 'lib/hca/military_information.rb', line 124

def 
  latest_service_episode&.begin_date
end

#latest_service_episodeObject



76
77
78
# File 'lib/hca/military_information.rb', line 76

def latest_service_episode
  service_episodes_by_date.try(:[], 0)
end

#military_service_episodesObject



80
81
82
83
84
# File 'lib/hca/military_information.rb', line 80

def military_service_episodes
  service_history.episodes.find_all do |episode|
    episode.service_type == 'Military Service'
  end
end

#post_nov111998_combatObject



106
107
108
109
110
111
112
# File 'lib/hca/military_information.rb', line 106

def post_nov111998_combat
  deployments.each do |deployment|
    return true if Date.parse(deployment['deployment_end_date']) > NOV_1998
  end

  false
end

#service_episodes_by_dateObject



62
63
64
65
66
67
68
69
70
# File 'lib/hca/military_information.rb', line 62

def service_episodes_by_date
  @service_episodes_by_date ||= military_service_episodes.sort_by do |ep|
    if ep.end_date.blank?
      Time.zone.today + 3650
    else
      Date.parse(ep.end_date)
    end
  end.reverse
end

#sw_asia_combatObject



86
87
88
# File 'lib/hca/military_information.rb', line 86

def sw_asia_combat
  deployed_to?(SOUTHWEST_ASIA, GULF_WAR_RANGE)
end