Class: Vines::Stream::Parser
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- Vines::Stream::Parser
- Includes:
- Nokogiri::XML
- Defined in:
- lib/vines/stream/parser.rb
Constant Summary collapse
- STREAM_NAME =
'stream'.freeze
- STREAM_URI =
'http://etherx.jabber.org/streams'.freeze
- IGNORE =
NAMESPACES.values_at(:client, :component, :server)
Instance Method Summary collapse
- #<<(data) ⇒ Object
- #characters(chars) ⇒ Object (also: #cdata_block)
- #end_element_namespace(name, prefix = nil, uri = nil) ⇒ Object
-
#initialize(&block) ⇒ Parser
constructor
A new instance of Parser.
- #start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = []) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Parser
Returns a new instance of Parser.
11 12 13 14 15 |
# File 'lib/vines/stream/parser.rb', line 11 def initialize(&block) @listeners, @node = Hash.new {|h, k| h[k] = []}, nil @parser = Nokogiri::XML::SAX::PushParser.new(self) instance_eval(&block) if block end |
Instance Method Details
#<<(data) ⇒ Object
23 24 25 26 |
# File 'lib/vines/stream/parser.rb', line 23 def <<(data) @parser << data self end |
#characters(chars) ⇒ Object Also known as: cdata_block
49 50 51 |
# File 'lib/vines/stream/parser.rb', line 49 def characters(chars) @node << Text.new(chars, @node.document) if @node end |
#end_element_namespace(name, prefix = nil, uri = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vines/stream/parser.rb', line 38 def end_element_namespace(name, prefix=nil, uri=nil) if stream?(name, uri) notify(:stream_close) elsif @node.parent != @node.document @node = @node.parent else notify(:stanza, @node) @node = nil end end |
#start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = []) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/vines/stream/parser.rb', line 28 def start_element_namespace(name, attrs=[], prefix=nil, uri=nil, ns=[]) el = node(name, attrs, prefix, uri, ns) if stream?(name, uri) notify(:stream_open, el) else @node << el if @node @node = el end end |