Sha256: 02fe1f1c5c40cb2b4b926af022c386b5c273124ede0d1ffc93d942fd2451e045
Contents?: true
Size: 1021 Bytes
Versions: 6
Compression:
Stored size: 1021 Bytes
Contents
module Seiun module XMLParsers class StreamListener include REXML::StreamListener def initialize(find_tag, callback) @find_tag = find_tag @callback = callback @stack = [] end 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 def text(text) text = text.strip return if text.empty? @stack.last << text if @current end 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 end end end
Version data entries
6 entries across 6 versions & 1 rubygems