class Threatinator::Parsers::XML::Parser
Attributes
pattern[R]
Public Class Methods
new(opts = {})
click to toggle source
@param [Hash] opts Parameters hash @option opts [Threatinator::Parsers::XML::Pattern] :pattern The pattern
object to use for matching chunks of XML
Calls superclass method
Threatinator::Parser::new
# File lib/threatinator/parsers/xml/parser.rb, line 16 def initialize(opts = {}) @pattern = opts.delete(:pattern) or raise ArgumentError.new("Missing argument :pattern") @max_cursor_depth = @pattern.max_depth - 1 super(opts) end
Public Instance Methods
==(other)
click to toggle source
Calls superclass method
Threatinator::Parser#==
# File lib/threatinator/parsers/xml/parser.rb, line 22 def ==(other) @pattern == other.pattern && super(other) end
run(io) { |record| ... }
click to toggle source
@param [IO] io @yield [record] Gives one line to the block @yieldparam record [Threatinator::Parser::XML::Record] a record
# File lib/threatinator/parsers/xml/parser.rb, line 30 def run(io) stack = Path.new callback = lambda do |element| yield(Threatinator::Parsers::XML::Record.new(element)) end doc = SAXDocument.new(@pattern, callback) parser = Nokogiri::XML::SAX::Parser.new(doc) parser.parse(io) end