Class: XMPP4EM::XmppPushParser
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- XMPP4EM::XmppPushParser
- Defined in:
- lib/xmpp4em/base_connection.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
Returns the value of attribute current.
-
#started ⇒ Object
Returns the value of attribute started.
Instance Method Summary collapse
- #characters(text) ⇒ Object
- #encode2utf8(text) ⇒ Object
- #end_element(name) ⇒ Object
- #process(&block) ⇒ Object
- #start_element(name, attrs) ⇒ Object
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current.
14 15 16 |
# File 'lib/xmpp4em/base_connection.rb', line 14 def current @current end |
#started ⇒ Object
Returns the value of attribute started.
13 14 15 |
# File 'lib/xmpp4em/base_connection.rb', line 13 def started @started end |
Instance Method Details
#characters(text) ⇒ Object
56 57 58 |
# File 'lib/xmpp4em/base_connection.rb', line 56 def characters text @current.text = @current.text.to_s + encode2utf8(text) if @current end |
#encode2utf8(text) ⇒ Object
20 21 22 |
# File 'lib/xmpp4em/base_connection.rb', line 20 def encode2utf8(text) text end |
#end_element(name) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/xmpp4em/base_connection.rb', line 43 def end_element name if name == 'stream' and @current.nil? @started = false else if @current.parent @current = @current.parent else @process.call(@current) @current = nil end end end |
#process(&block) ⇒ Object
16 17 18 |
# File 'lib/xmpp4em/base_connection.rb', line 16 def process(&block) @process=block end |
#start_element(name, attrs) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/xmpp4em/base_connection.rb', line 24 def start_element name, attrs e = ::REXML::Element.new(name) attrs.each { |a| a_name, a_value = *a if a_name =~ /^xmlns:(.+)$/ e.add_attribute($1, a_value.to_s) else e.add_namespace(a_name, a_value) end } if attrs.length > 0 @current = @current.nil? ? e : @current.add_element(e) if @current.name == 'stream' and not @started @started = true @process.call(@current) @current = nil end end |