Class: SadsXml::Sads
- Inherits:
-
Object
- Object
- SadsXml::Sads
- Defined in:
- lib/sads_xml/sads.rb
Constant Summary collapse
- DEFAULTS =
{ :navigation => { :type => 'nav' } }
Instance Attribute Summary collapse
-
#banner_position ⇒ Object
Returns the value of attribute banner_position.
-
#banner_targets ⇒ Object
Returns the value of attribute banner_targets.
-
#inputs ⇒ Object
Returns the value of attribute inputs.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#navigations ⇒ Object
Returns the value of attribute navigations.
-
#request_attributes ⇒ Object
Returns the value of attribute request_attributes.
-
#sanitize(text) ⇒ Object
Returns the value of attribute sanitize.
-
#sms_message ⇒ Object
Returns the value of attribute sms_message.
-
#submit_page ⇒ Object
Returns the value of attribute submit_page.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #add_attribute(req_attribute) ⇒ Object
- #add_input(input) ⇒ Object
- #add_navigation(link, navigation_id = :default) ⇒ Object
-
#initialize ⇒ Sads
constructor
A new instance of Sads.
- #message=(message) ⇒ Object
- #one_ussd_message ⇒ Object
- #one_ussd_message_characters_left ⇒ Object
- #set_message(id, message) ⇒ Object
- #to_sads ⇒ Object
- #ussd_length ⇒ Object
Constructor Details
#initialize ⇒ Sads
Returns a new instance of Sads.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sads_xml/sads.rb', line 35 def initialize @sanitize = false @title = '' @inputs = [] @navigations = { :default => [] } @messages = { :top => '', :bottom => '' } @banner_targets = [] @banner_position = :bottom @request_attributes = [] end |
Instance Attribute Details
#banner_position ⇒ Object
Returns the value of attribute banner_position.
26 27 28 |
# File 'lib/sads_xml/sads.rb', line 26 def @banner_position end |
#banner_targets ⇒ Object
Returns the value of attribute banner_targets.
26 27 28 |
# File 'lib/sads_xml/sads.rb', line 26 def @banner_targets end |
#inputs ⇒ Object
Returns the value of attribute inputs.
26 27 28 |
# File 'lib/sads_xml/sads.rb', line 26 def inputs @inputs end |
#messages ⇒ Object
Returns the value of attribute messages.
26 27 28 |
# File 'lib/sads_xml/sads.rb', line 26 def @messages end |
#navigations ⇒ Object
Returns the value of attribute navigations.
26 27 28 |
# File 'lib/sads_xml/sads.rb', line 26 def @navigations end |
#request_attributes ⇒ Object
Returns the value of attribute request_attributes.
26 27 28 |
# File 'lib/sads_xml/sads.rb', line 26 def request_attributes @request_attributes end |
#sanitize(text) ⇒ Object
Returns the value of attribute sanitize.
26 27 28 |
# File 'lib/sads_xml/sads.rb', line 26 def sanitize @sanitize end |
#sms_message ⇒ Object
Returns the value of attribute sms_message.
26 27 28 |
# File 'lib/sads_xml/sads.rb', line 26 def @sms_message end |
#submit_page ⇒ Object
Returns the value of attribute submit_page.
26 27 28 |
# File 'lib/sads_xml/sads.rb', line 26 def submit_page @submit_page end |
#title ⇒ Object
Returns the value of attribute title.
26 27 28 |
# File 'lib/sads_xml/sads.rb', line 26 def title @title end |
Instance Method Details
#add_attribute(req_attribute) ⇒ Object
95 96 97 |
# File 'lib/sads_xml/sads.rb', line 95 def add_attribute(req_attribute) @request_attributes<< req_attribute end |
#add_input(input) ⇒ Object
103 104 105 |
# File 'lib/sads_xml/sads.rb', line 103 def add_input(input) @inputs<< input end |
#add_navigation(link, navigation_id = :default) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/sads_xml/sads.rb', line 86 def (link, = :default) @navigations[] = [] if @navigations[].nil? # workaround for SADS Absolute Path #link[:pageId].gsub!(/^\/yp_mobile\//, '') unless link[:pageId].match(/\.html$/) @navigations[]<< DEFAULTS[:navigation].merge(link) end |
#message=(message) ⇒ Object
46 47 48 |
# File 'lib/sads_xml/sads.rb', line 46 def () self.(:default, ) end |
#one_ussd_message ⇒ Object
78 79 80 |
# File 'lib/sads_xml/sads.rb', line 78 def ussd_length <= 160 end |
#one_ussd_message_characters_left ⇒ Object
82 83 84 |
# File 'lib/sads_xml/sads.rb', line 82 def 160 - ussd_length end |
#set_message(id, message) ⇒ Object
99 100 101 |
# File 'lib/sads_xml/sads.rb', line 99 def (id, ) @messages[id.to_sym] = end |
#to_sads ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/sads_xml/sads.rb', line 112 def to_sads xml = Builder::XmlMarkup.new xml.instruct! xml.page :version => "2.0", "xmlns:meta" => "http://whoisd.eyeline.com/sads/meta" do xml.title sanitize(@title), :id => '' @messages.each do |key, | object_hash = {} object_hash[:id] = key.to_s unless key == :default xml.div object_hash do unless .blank? xml.div do lines = sanitize().split("\n").reverse while line = lines.pop xml.text! line xml.br if lines.any? end end end if @banner_position.to_s == key.to_s and @banner_targets.any? xml.br xml.br unless .blank? xml. :banner, :target => @banner_targets.join(',') end end end xml.div sanitize(@sms_message), :type => 'sms' unless .blank? if @inputs.any? xml.div do @inputs.each do |input| xml.input input end end end .each do |key, links| if links.any? object_hash = {} object_hash[:id] = key.to_s unless key == :default xml. object_hash do links.each do |link| xml.link sanitize(link[:title].strip), link.except(:title) end end end # eo if links.any? if @inputs.any? xml. :id => 'submit' do xml.link :accesskey => '1', :pageId => @submit_page end end end if @request_attributes.any? xml.attributes do @request_attributes.each do |attribute| xml.attribute attribute end end end end end |
#ussd_length ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/sads_xml/sads.rb', line 56 def ussd_length counter = 0 counter += @title.length + 2 unless @title.blank? @messages.each do |key, | counter += .length + 1 unless .blank? end @navigations.each do |key, links| links.each do |link| counter += link[:title].length + link[:accesskey].length + 2 end end @inputs.each do |input| counter += input[:title].length + 2 end counter -= 1 return counter end |