Class: SmscManager::Sms
- Inherits:
-
Object
- Object
- SmscManager::Sms
- Includes:
- StompMessage::XmlHelper
- Defined in:
- lib/smsc_manager/sms.rb
Overview
and strips out the unnecessary junk
Constant Summary collapse
- @@MAX_SIZE =
3*160 # max 1500 characters, change if your smsc suports less
1500
- @@msisdn_valid_prefix =
%w{ 63999 999 0999 1000 888 +63999 }
Instance Attribute Summary collapse
-
#destination ⇒ Object
, :orig_txt.
-
#source ⇒ Object
, :orig_txt.
-
#text ⇒ Object
, :orig_txt.
Class Method Summary collapse
- .check_destination(dst) ⇒ Object
- .load_xml(xml_string) ⇒ Object
- .max_length ⇒ Object
- .starts_with?(prefix, dest) ⇒ Boolean
-
.valid ⇒ Object
create new sms, limit the text, src is 1000.
Instance Method Summary collapse
- #get_message_content ⇒ Object
-
#initialize(txt, dest, src = '888') ⇒ Sms
constructor
A new instance of Sms.
- #limit_text(val) ⇒ Object
- #prefix_test ⇒ Object
- #strip_text(txt) ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(txt, dest, src = '888') ⇒ Sms
Returns a new instance of Sms.
33 34 35 36 37 38 39 |
# File 'lib/smsc_manager/sms.rb', line 33 def initialize(txt,dest,src='888') # self.orig_txt=txt self.destination=dest self.source=src self.text=strip_text(txt) raise InvalidPrefix.new("invalid prefix: valid prefix area:" + Sms.valid ) if !prefix_test end |
Instance Attribute Details
#destination ⇒ Object
, :orig_txt
14 15 16 |
# File 'lib/smsc_manager/sms.rb', line 14 def destination @destination end |
#source ⇒ Object
, :orig_txt
14 15 16 |
# File 'lib/smsc_manager/sms.rb', line 14 def source @source end |
#text ⇒ Object
, :orig_txt
14 15 16 |
# File 'lib/smsc_manager/sms.rb', line 14 def text @text end |
Class Method Details
.check_destination(dst) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/smsc_manager/sms.rb', line 43 def self.check_destination(dst) flag = false @@msisdn_valid_prefix.each { |w| k= Sms.starts_with? w , dst flag=true if k } flag end |
.load_xml(xml_string) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/smsc_manager/sms.rb', line 58 def self.load_xml(xml_string) doc=REXML::Document.new(xml_string) dest=REXML::XPath.first(doc, "//destination").text src=REXML::XPath.first(doc, "//source").text text=REXML::XPath.first(doc, "//text").text sms=SmscManager::Sms.new(text,dest,src) end |
.max_length ⇒ Object
15 16 17 |
# File 'lib/smsc_manager/sms.rb', line 15 def self.max_length @@MAX_SIZE end |
.starts_with?(prefix, dest) ⇒ Boolean
28 29 30 31 32 |
# File 'lib/smsc_manager/sms.rb', line 28 def self.starts_with?(prefix,dest) prefix = prefix.to_s return false if dest == nil dest[0, prefix.length] == prefix end |
.valid ⇒ Object
create new sms, limit the text, src is 1000
20 21 22 23 24 |
# File 'lib/smsc_manager/sms.rb', line 20 def self.valid sentence=" " @@msisdn_valid_prefix.each {|t| sentence << t <<" " } sentence end |
Instance Method Details
#get_message_content ⇒ Object
25 26 27 |
# File 'lib/smsc_manager/sms.rb', line 25 def self.text end |
#limit_text(val) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/smsc_manager/sms.rb', line 65 def limit_text(val) #limit to @@MAX_SIZE characters ret="" size=[val.size,@@MAX_SIZE].min-1 # 0.upto(size) do |i| # ret << val[i] # end ret=val[0..size] ret end |
#prefix_test ⇒ Object
40 41 42 |
# File 'lib/smsc_manager/sms.rb', line 40 def prefix_test Sms.check_destination(self.destination) end |
#strip_text(txt) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/smsc_manager/sms.rb', line 75 def strip_text(txt) # puts "text is #{txt} nil #{txt==nil}" txt= " " if txt==nil result=txt.gsub(/@/,"(at)") # replace all at signs return result # result=result.gsub(/\n/," ") # replace all new lines return result # result=result.gsub(/\r/," ") # replace all new lines return result result=result.gsub('_',"-") # replace all new lines return result # result=result.gsub(/-/," ") # replace all - with space...angelo bug return result # result=result4.gsub(/\//,"") # replace all new lines return result limit_text(result) end |
#to_xml ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/smsc_manager/sms.rb', line 50 def to_xml msg_xml = REXML::Element.new "sms" msg_xml =self.add_elements(msg_xml) msg_xml.to_s # doc= REXML::Document.new sms_xml.to_s # doc.to_s end |