Class: BGS::Dependents

Inherits:
Object
  • Object
show all
Defined in:
lib/bgs/dependents.rb

Instance Method Summary collapse

Constructor Details

#initialize(proc_id:, payload:, user:) ⇒ Dependents

Returns a new instance of Dependents.



7
8
9
10
11
12
13
14
# File 'lib/bgs/dependents.rb', line 7

def initialize(proc_id:, payload:, user:)
  @proc_id = proc_id
  @payload = payload
  @dependents = []
  @dependents_application = @payload['dependents_application']
  @user = user
  @views = payload['view:selectable686_options']
end

Instance Method Details

#bgs_serviceObject (private)



84
85
86
# File 'lib/bgs/dependents.rb', line 84

def bgs_service
  @bgs_service ||= BGS::Service.new(@user)
end

#create_allObject



16
17
18
19
20
21
# File 'lib/bgs/dependents.rb', line 16

def create_all
  report_deaths if @views['report_death']
  report_divorce if @dependents_application['report_divorce']

  @dependents
end

#person_params(calling_object, participant, dependent_info) ⇒ Object (private)



73
74
75
# File 'lib/bgs/dependents.rb', line 73

def person_params(calling_object, participant, dependent_info)
  calling_object.create_person_params(@proc_id, participant[:vnp_ptcpnt_id], dependent_info)
end

#report_deathsObject (private)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/bgs/dependents.rb', line 25

def report_deaths
  @dependents_application['deaths'].each do |death_info|
    death = BGSDependents::Death.new(death_info)
    relationship_types = death.relationship_type(death_info)

    # next if relationship_types[:family] == 'Child' # BGS does not support child death at this time

    formatted_info = death.format_info
    death_info['location']['state_code'] = death_info['location'].delete('state')
    participant = bgs_service.create_participant(@proc_id)
    bgs_service.create_person(person_params(death, participant, formatted_info))
    # Need to add death location once BGS adds support for this functionality

    @dependents << death.serialize_dependent_result(
      participant,
      relationship_types[:participant],
      relationship_types[:family],
      {
        type: 'death',
        dep_has_income_ind: formatted_info['dependent_income'],
        end_date: formatted_info['death_date']
      }
    )
  end
end

#report_divorceObject (private)



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/bgs/dependents.rb', line 51

def report_divorce
  divorce = BGSDependents::Divorce.new(@dependents_application['report_divorce'])
  formatted_info = divorce.format_info
  participant = bgs_service.create_participant(@proc_id)
  bgs_service.create_person(person_params(divorce, participant, formatted_info))

  @dependents << divorce.serialize_dependent_result(
    participant,
    'Spouse',
    'Spouse',
    {
      divorce_state: formatted_info['divorce_state'],
      divorce_city: formatted_info['divorce_city'],
      divorce_country: formatted_info['divorce_country'],
      end_date: formatted_info['end_date'],
      marriage_termination_type_code: formatted_info['marriage_termination_type_code'],
      type: 'divorce',
      dep_has_income_ind: formatted_info['spouse_income']
    }
  )
end

#send_address(calling_object, participant, address_info) ⇒ Object (private)



77
78
79
80
81
82
# File 'lib/bgs/dependents.rb', line 77

def send_address(calling_object, participant, address_info)
  address = calling_object.generate_address(address_info)
  address_params = calling_object.create_address_params(@proc_id, participant[:vnp_ptcpnt_id], address)

  bgs_service.create_address(address_params)
end