Class: Dovado::Router::Sms::Message
- Inherits:
-
Object
- Object
- Dovado::Router::Sms::Message
- Includes:
- Celluloid
- Defined in:
- lib/dovado/router/sms/message.rb
Overview
A text message (SMS).
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
Message body.
-
#encoding ⇒ Encoding
readonly
Message text encoding.
-
#from ⇒ String
readonly
Message sender.
-
#id ⇒ String, ...
readonly
Message Id.
-
#pdus ⇒ Array
readonly
Message PDU’s.
-
#sent ⇒ DateTime
readonly
Message send timestamp.
Class Method Summary collapse
-
.from_string(string = nil) ⇒ Message
Create a new Message object from a
String
.
Instance Method Summary collapse
-
#initialize(args = nil) ⇒ Message
constructor
Create a new Message object.
Constructor Details
#initialize(args = nil) ⇒ Message
Create a new Dovado::Router::Sms::Message object.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dovado/router/sms/message.rb', line 40 def initialize(args=nil) unless args.nil? @id = args[:id] unless args[:id].nil? @body = args[:body] unless args[:body].nil? @pdus = args[:pdus] unless args[:pdus].nil? @from = args[:from] unless args[:from].nil? @sent = args[:sent] unless args[:sent].nil? @encoding = args[:encoding] unless args[:encoding].nil? end end |
Instance Attribute Details
#body ⇒ String (readonly)
Message body.
17 18 19 |
# File 'lib/dovado/router/sms/message.rb', line 17 def body @body end |
#encoding ⇒ Encoding (readonly)
Message text encoding.
29 30 31 |
# File 'lib/dovado/router/sms/message.rb', line 29 def encoding @encoding end |
#from ⇒ String (readonly)
Message sender.
23 24 25 |
# File 'lib/dovado/router/sms/message.rb', line 23 def from @from end |
#id ⇒ String, ... (readonly)
Message Id.
14 15 16 |
# File 'lib/dovado/router/sms/message.rb', line 14 def id @id end |
#pdus ⇒ Array (readonly)
Message PDU’s.
20 21 22 |
# File 'lib/dovado/router/sms/message.rb', line 20 def pdus @pdus end |
#sent ⇒ DateTime (readonly)
Message send timestamp.
26 27 28 |
# File 'lib/dovado/router/sms/message.rb', line 26 def sent @sent end |
Class Method Details
.from_string(string = nil) ⇒ Message
Create a new Dovado::Router::Sms::Message object from a String
.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/dovado/router/sms/message.rb', line 55 def self.from_string(string=nil) hash = ThreadSafe::Cache.new = "" array = string.split("\n") array.each do |row| row_array = row.split(':') if row_array.length == 2 key = row_array[0].downcase val = row_array[1] case key.strip when 'from' hash[:from] = val.strip when 'alphabet' begin hash[:encoding] = Encoding.find(val.strip) rescue ArgumentError hash[:encoding] = Encoding::UTF_8 end when 'id' hash[:id] = val.strip.to_i end elsif row_array.length > 2 sent = row.match(/[Ss]ent\:\W(.*)/) hash[:sent] = DateTime.parse(sent[1].strip) else unless row.downcase =~ /end of sms/ += "#{row}\n" end end end hash[:body] = .tr(">>", "").tr("\x17", "").strip.force_encoding(hash[:encoding]) Message.new(hash) end |