Class: Threatinator::Parsers::XML::Parser
- Inherits:
-
Threatinator::Parser
- Object
- Threatinator::Parser
- Threatinator::Parsers::XML::Parser
- Defined in:
- lib/threatinator/parsers/xml/parser.rb
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(opts = {}) ⇒ Parser
constructor
A new instance of Parser.
- #run(io) {|record| ... } ⇒ Object
Methods inherited from Threatinator::Parser
Constructor Details
#initialize(opts = {}) ⇒ Parser
Returns a new instance of Parser.
16 17 18 19 20 |
# 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 |
Instance Attribute Details
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
12 13 14 |
# File 'lib/threatinator/parsers/xml/parser.rb', line 12 def pattern @pattern end |
Instance Method Details
#==(other) ⇒ Object
22 23 24 25 |
# File 'lib/threatinator/parsers/xml/parser.rb', line 22 def ==(other) @pattern == other.pattern && super(other) end |
#run(io) {|record| ... } ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# 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 |