Class: HCA::MilitaryInformation
- Inherits:
-
Object
- Object
- HCA::MilitaryInformation
- 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
- #deployed_to?(countries, date_range) ⇒ Boolean
- #deployments ⇒ Object
- #discharge_type ⇒ Object
- #hca_last_service_branch ⇒ Object
-
#initialize(user) ⇒ MilitaryInformation
constructor
A new instance of MilitaryInformation.
- #last_discharge_date ⇒ Object
- #last_entry_date ⇒ Object
- #latest_service_episode ⇒ Object
- #military_service_episodes ⇒ Object
- #post_nov111998_combat ⇒ Object
- #service_episodes_by_date ⇒ Object
- #sw_asia_combat ⇒ Object
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
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 |
#deployments ⇒ Object
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_type ⇒ Object
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_branch ⇒ Object
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_date ⇒ Object
120 121 122 |
# File 'lib/hca/military_information.rb', line 120 def last_discharge_date latest_service_episode&.end_date end |
#last_entry_date ⇒ Object
124 125 126 |
# File 'lib/hca/military_information.rb', line 124 def last_entry_date latest_service_episode&.begin_date end |
#latest_service_episode ⇒ Object
76 77 78 |
# File 'lib/hca/military_information.rb', line 76 def latest_service_episode service_episodes_by_date.try(:[], 0) end |
#military_service_episodes ⇒ Object
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_combat ⇒ Object
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_date ⇒ Object
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_combat ⇒ Object
86 87 88 |
# File 'lib/hca/military_information.rb', line 86 def sw_asia_combat deployed_to?(SOUTHWEST_ASIA, GULF_WAR_RANGE) end |