class Seiun::XMLParsers::StreamListener
Public Class Methods
new(find_tag, callback)
click to toggle source
# File lib/seiun/xml_parsers/stream_listener.rb, line 6 def initialize(find_tag, callback) @find_tag = find_tag @callback = callback @stack = [] end
Public Instance Methods
tag_end(name)
click to toggle source
# File lib/seiun/xml_parsers/stream_listener.rb, line 32 def tag_end(name) if @stack.size == 1 && name == @find_tag @callback.call(Marshal.load(Marshal.dump(@current))) @current, @stack = nil, [] elsif @current pop_tag = @stack.pop end end
tag_start(name, attrs)
click to toggle source
# File lib/seiun/xml_parsers/stream_listener.rb, line 12 def tag_start(name, attrs) if @stack.empty? && name == @find_tag element = [] element << attrs unless attrs.empty? @current = element @stack = [ element ] elsif @current element = [] element << attrs unless attrs.empty? @stack.last << { name => element } @stack.push(element) end end
text(text)
click to toggle source
# File lib/seiun/xml_parsers/stream_listener.rb, line 26 def text(text) text = text.strip return if text.empty? @stack.last << text if @current end