Class: VAProfile::Models::Telephone

Inherits:
Base
  • Object
show all
Includes:
Concerns::Defaultable, Concerns::Expirable
Defined in:
lib/va_profile/models/telephone.rb

Constant Summary collapse

VALID_AREA_CODE_REGEX =
/[0-9]+/
VALID_PHONE_NUMBER_REGEX =
/[^a-zA-Z]+/
MOBILE =
'MOBILE'
HOME =
'HOME'
WORK =
'WORK'
FAX =
'FAX'
TEMPORARY =
'TEMPORARY'
PHONE_TYPES =
[MOBILE, HOME, WORK, FAX, TEMPORARY].freeze

Constants inherited from Base

Base::SOURCE_SYSTEM

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Defaultable

#set_defaults

Class Method Details

.build_from(body) ⇒ VAProfile::Models::Telephone

Converts a decoded JSON response from VAProfile to an instance of the Telephone model

Parameters:

  • body (Hash)

    the decoded response body from VAProfile

Returns:



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/va_profile/models/telephone.rb', line 127

def self.build_from(body)
  VAProfile::Models::Telephone.new(
    area_code: body['area_code'],
    country_code: body['country_code'],
    created_at: body['create_date'],
    extension: body['phone_number_ext'],
    id: body['telephone_id'],
    is_international: body['international_indicator'],
    is_textable: body['text_message_capable_ind'],
    is_text_permitted: body['text_message_perm_ind'],
    is_voicemailable: body['voice_mail_acceptable_ind'],
    phone_number: body['phone_number'],
    phone_type: body['phone_type'],
    source_date: body['source_date'],
    transaction_id: body['tx_audit_id'],
    is_tty: body['tty_ind'],
    updated_at: body['update_date'],
    vet360_id: body['vet360_id'],
    effective_end_date: body['effective_end_date'],
    effective_start_date: body['effective_start_date']
  )
end

Instance Method Details

#formatted_phoneObject



82
83
84
85
86
87
88
89
90
91
# File 'lib/va_profile/models/telephone.rb', line 82

def formatted_phone
  return if phone_number.blank?

  # TODO: support international numbers

  return_val = "(#{area_code}) #{phone_number[0..2]}-#{phone_number[3..7]}"
  return_val += " Ext. #{extension}" if extension.present?

  return_val
end

#in_jsonString

Converts an instance of the Telphone model to a JSON encoded string suitable for use in the body of a request to VAProfile

rubocop:disable Metrics/MethodLength

Returns:

  • (String)

    JSON-encoded string suitable for requests to VAProfile



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/va_profile/models/telephone.rb', line 99

def in_json
  {
    bio: {
      areaCode: @area_code,
      countryCode: @country_code,
      internationalIndicator: @is_international,
      originatingSourceSystem: SOURCE_SYSTEM,
      phoneNumber: @phone_number,
      phoneNumberExt: @extension,
      phoneType: @phone_type,
      sourceDate: @source_date,
      sourceSystemUser: @source_system_user,
      telephoneId: @id,
      textMessageCapableInd: @is_textable,
      textMessagePermInd: @is_text_permitted,
      ttyInd: @is_tty,
      vet360Id: @vet360_id,
      voiceMailAcceptableInd: @is_voicemailable,
      effectiveStartDate: @effective_start_date,
      effectiveEndDate: @effective_end_date
    }
  }.to_json
end