Class: VAProfile::MilitaryPersonnel::ServiceHistoryResponse
- Inherits:
-
Response
show all
- Defined in:
- lib/va_profile/military_personnel/service_history_response.rb
Constant Summary
Common::Client::Concerns::ServiceStatus::RESPONSE_STATUS
Instance Attribute Summary
Attributes inherited from Common::Base
#errors_hash, #metadata
Class Method Summary
collapse
Methods inherited from Response
#cache?, #initialize, #metadata, #ok?, #response_status
#changed, #changed?, #changes, default_sort, filterable_attributes, #initialize, max_per_page, per_page, sortable_attributes
Class Method Details
.from(current_user, raw_response = nil) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/va_profile/military_personnel/service_history_response.rb', line 14
def self.from(current_user, raw_response = nil)
body = raw_response&.body
episodes = []
episodes += get_military_service_episodes(body)
episodes += get_academy_attendance_episodes(body) if include_academy_attendance?(current_user)
new(
raw_response&.status,
episodes: episodes ? sort_by_begin_date(episodes) : episodes,
uniformed_service_initial_entry_date: get_uniformed_service_initial_entry_date(body),
release_from_active_duty_date: get_release_from_active_duty_date(body),
vet_status_eligibility: get_eligibility(episodes)
)
end
|
.get_academy_attendance_episodes(body) ⇒ Object
.get_eligibility(episodes) ⇒ Object
.get_episodes(body, episode_type) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/va_profile/military_personnel/service_history_response.rb', line 38
def self.get_episodes(body, episode_type)
return nil unless body && episode_type
episodes = body&.dig(
'profile',
'military_person',
'military_service_history',
episode_type)
episodes&.map { |e| VAProfile::Models::ServiceHistory.build_from(e, episode_type) }
end
|
.get_military_service_episodes(body) ⇒ Object
.get_release_from_active_duty_date(body) ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/va_profile/military_personnel/service_history_response.rb', line 58
def self.get_release_from_active_duty_date(body)
body&.dig(
'profile',
'military_person',
'military_service_history',
'release_from_active_duty_date')
end
|
.get_uniformed_service_initial_entry_date(body) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/va_profile/military_personnel/service_history_response.rb', line 50
def self.get_uniformed_service_initial_entry_date(body)
body&.dig(
'profile',
'military_person',
'military_service_history',
'uniformed_service_initial_entry_date')
end
|
.include_academy_attendance?(current_user) ⇒ Boolean
70
71
72
|
# File 'lib/va_profile/military_personnel/service_history_response.rb', line 70
def self.include_academy_attendance?(current_user)
Flipper.enabled?(:profile_show_military_academy_attendance, current_user)
end
|
.sort_by_begin_date(service_episodes) ⇒ Object
66
67
68
|
# File 'lib/va_profile/military_personnel/service_history_response.rb', line 66
def self.sort_by_begin_date(service_episodes)
service_episodes.sort_by { |se| se.begin_date || Time.zone.today + 3650 }
end
|