Class: PduSms::MessageReference
- Inherits:
-
Object
- Object
- PduSms::MessageReference
- Defined in:
- lib/pdu_sms/message_reference.rb
Class Method Summary collapse
-
.cut_off_pdu(pdu, part = :all, type = :ms) ⇒ Object
tail current.
- .decode_ms(pdu) ⇒ Object
- .encode_ms(num) ⇒ Object
Instance Method Summary collapse
- #get_hex ⇒ Object
- #get_mr ⇒ Object
-
#initialize(num) ⇒ MessageReference
constructor
A new instance of MessageReference.
Constructor Details
#initialize(num) ⇒ MessageReference
Returns a new instance of MessageReference.
4 5 6 7 8 9 10 |
# File 'lib/pdu_sms/message_reference.rb', line 4 def initialize(num) if (0..255).include?(num) @mr = num else raise ArgumentError, 'The "num" is incorrect' end end |
Class Method Details
.cut_off_pdu(pdu, part = :all, type = :ms) ⇒ Object
tail current
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pdu_sms/message_reference.rb', line 20 def MessageReference.cut_off_pdu(pdu, part=:all, type=:ms) # tail current part_pdu = PDUType.cut_off_pdu(pdu, :tail) raise ArgumentError, 'The "pdu" is incorrect' if part_pdu.length < 2 current = part_pdu[0..1] tail = part_pdu[2..-1] 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/message_reference.rb', line 16 def MessageReference.decode_ms(pdu) new(MessageReference.cut_off_pdu(pdu, :current, :ms).to_i(2)).freeze end |
.encode_ms(num) ⇒ Object
12 13 14 |
# File 'lib/pdu_sms/message_reference.rb', line 12 def MessageReference.encode_ms(num) new(num).freeze end |
Instance Method Details
#get_hex ⇒ Object
32 33 34 |
# File 'lib/pdu_sms/message_reference.rb', line 32 def get_hex '%02X' % @mr end |
#get_mr ⇒ Object
36 37 38 |
# File 'lib/pdu_sms/message_reference.rb', line 36 def get_mr @mr end |