Class: PduSms::DestinationAddress

Inherits:
Phone
  • Object
show all
Defined in:
lib/pdu_sms/destination_address.rb

Instance Attribute Summary

Attributes inherited from Phone

#number_plan_identifier, #type_number

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Phone

#get_phone_number

Constructor Details

#initialize(type = false, data = false, number_play_identifier = false, type_number = false) ⇒ DestinationAddress

Returns a new instance of DestinationAddress.



4
5
6
7
8
9
10
# File 'lib/pdu_sms/destination_address.rb', line 4

def initialize(type=false, data=false, number_play_identifier=false, type_number=false)
  if type == :decode_ms
    _set_pdu_hex data
  elsif type == :encode_ms
    _set_phone_number data, number_play_identifier, type_number
  end
end

Class Method Details

.cut_off_pdu(pdu, part = :all, type = :ms) ⇒ Object

tail current

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pdu_sms/destination_address.rb', line 20

def DestinationAddress.cut_off_pdu(pdu, part=:all, type=:ms) # tail current
  part_pdu = MessageReference.cut_off_pdu(pdu, :tail)
  raise ArgumentError, 'The "pdu" is incorrect' if part_pdu.length < 4
  length = part_pdu[0..1].to_i(16)
  if length % 2 == 0
    current = part_pdu[0..length+3]
    tail = part_pdu[length+4..-1]
  else
    current = part_pdu[0..length+4]
    tail = part_pdu[length+5..-1]
  end
  case part
    when :current then current
    when :tail then tail
    else [current,tail]
  end
end

.decode_ms(pdu) ⇒ Object



16
17
18
# File 'lib/pdu_sms/destination_address.rb', line 16

def DestinationAddress.decode_ms(pdu)
  new(:decode_ms, DestinationAddress.cut_off_pdu(pdu, :current, :ms)).freeze
end

.encode_ms(phone_number, number_play_identifier = false, type_number = false) ⇒ Object



12
13
14
# File 'lib/pdu_sms/destination_address.rb', line 12

def DestinationAddress.encode_ms(phone_number, number_play_identifier=false, type_number=false)
  new(:encode_ms, phone_number, number_play_identifier, type_number).freeze
end

Instance Method Details

#get_hexObject



38
39
40
# File 'lib/pdu_sms/destination_address.rb', line 38

def get_hex
  '%s%s' % [_address_length, _get_hex_type_and_phone]
end