Class: VAProfile::Models::CommunicationChannel

Inherits:
CommunicationBase show all
Defined in:
lib/va_profile/models/communication_channel.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#communication_permissionObject

Returns the value of attribute communication_permission.



10
11
12
# File 'lib/va_profile/models/communication_channel.rb', line 10

def communication_permission
  @communication_permission
end

#default_send_indicatorObject

Returns the value of attribute default_send_indicator.



9
10
11
# File 'lib/va_profile/models/communication_channel.rb', line 9

def default_send_indicator
  @default_send_indicator
end

#descriptionObject

Returns the value of attribute description.



9
10
11
# File 'lib/va_profile/models/communication_channel.rb', line 9

def description
  @description
end

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/va_profile/models/communication_channel.rb', line 9

def id
  @id
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/va_profile/models/communication_channel.rb', line 9

def name
  @name
end

Class Method Details

.create_from_api(communication_channel_data, communication_item_id, default_send_indicator, permission_res) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/va_profile/models/communication_channel.rb', line 16

def self.create_from_api(communication_channel_data,
                         communication_item_id,
                         default_send_indicator,
                         permission_res)
  communication_channel_model = new(
    id: communication_channel_data['communication_channel_id'],
    name: communication_channel_data['name'],
    description: communication_channel_data['description'],
    default_send_indicator:
  )

  permission = permission_res['bios']&.find do |permission_data|
    permission_data['communication_item_id'] == communication_item_id &&
      permission_data['communication_channel_id'] == communication_channel_data['communication_channel_id']
  end

  if permission.present?
    communication_channel_model.communication_permission = VAProfile::Models::CommunicationPermission.new(
      id: permission['communication_permission_id'],
      allowed: permission['allowed']
    )
  end

  communication_channel_model
end

Instance Method Details

#communication_permission_validObject (private)



52
53
54
55
56
# File 'lib/va_profile/models/communication_channel.rb', line 52

def communication_permission_valid
  if communication_permission.present? && communication_permission.invalid?
    errors.add(:communication_permission, communication_permission.errors.full_messages.join(','))
  end
end