Class: SimCard::ReceivedSmsMessage
- Inherits:
-
Object
- Object
- SimCard::ReceivedSmsMessage
- Defined in:
- lib/sim_card/received_sms_message.rb
Instance Attribute Summary collapse
-
#message_id ⇒ Object
readonly
Returns the value of attribute message_id.
-
#sender_number ⇒ Object
readonly
Returns the value of attribute sender_number.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
-
.load_messages(at_command_sender) ⇒ Object
parse raw output from SIM card and return list of ReceivedSmsMessage instances.
Instance Method Summary collapse
-
#initialize(message_id, sender_number, timestamp, text) ⇒ ReceivedSmsMessage
constructor
-
message_id : ID of the sms message as provided by the SIM card * sender_number : who sent the message * timestamp : time of message arrival * text : message text.
-
- #to_s ⇒ Object
Constructor Details
#initialize(message_id, sender_number, timestamp, text) ⇒ ReceivedSmsMessage
-
message_id : ID of the sms message as provided by the SIM card
-
sender_number : who sent the message
-
timestamp : time of message arrival
-
text : message text
34 35 36 37 38 39 |
# File 'lib/sim_card/received_sms_message.rb', line 34 def initialize , sender_number, , text @message_id = @sender_number = sender_number @timestamp = @text = text end |
Instance Attribute Details
#message_id ⇒ Object (readonly)
Returns the value of attribute message_id.
28 29 30 |
# File 'lib/sim_card/received_sms_message.rb', line 28 def @message_id end |
#sender_number ⇒ Object (readonly)
Returns the value of attribute sender_number.
28 29 30 |
# File 'lib/sim_card/received_sms_message.rb', line 28 def sender_number @sender_number end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
28 29 30 |
# File 'lib/sim_card/received_sms_message.rb', line 28 def text @text end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
28 29 30 |
# File 'lib/sim_card/received_sms_message.rb', line 28 def @timestamp end |
Class Method Details
.load_messages(at_command_sender) ⇒ Object
parse raw output from SIM card and return list of ReceivedSmsMessage instances. see SimCardTest for examples of raw SIM output.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sim_card/received_sms_message.rb', line 6 def self. at_command_sender raw_sim_output = at_command_sender.send "AT+CMGL=\"ALL\"" = [] raw_input2 = raw_sim_output[14..-1] # remove initial AT+CMGL="ALL"\n raw_input3 = (raw_input2 || '').split('+CMGL: ')[1..-1] (raw_input3 || []).each do || header, *text_lines = .split("\n") # +CMGL: 2,"REC READ","+421918987987","","13/08/20,19:00:44+08" , _, sender_number, _, date, time = header.gsub("\"", '').split(',') = DateTime.strptime (date + ' ' + time), '%y/%m/%d %H:%M:%S' = text_lines.join "\n" = ReceivedSmsMessage.new , sender_number, , << end return .reverse end |
Instance Method Details
#to_s ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/sim_card/received_sms_message.rb', line 41 def to_s <<STRING message id: #{@message_id} sender: #{@sender_number} timestamp: #{@timestamp} #{@text} STRING end |