class Threatinator::Parsers::XML::Pattern
Implements path matching behavior for use with the XML
parser. Aims to support a small subset of XPath behaviors, specifically for matching elements.
Public Class Methods
new(pathspec)
click to toggle source
@param [String] pathspec A specification of a path match.
# File lib/threatinator/parsers/xml/pattern.rb, line 10 def initialize(pathspec) parts = pathspec.split('/') leader_count = 0 while parts[0] == '' leader_count += 1 parts.shift end @path = Threatinator::Parsers::XML::Path.new(parts) @anchored = true if leader_count == 1 @anchored = true elsif leader_count == 2 @anchored = false else raise ArgumentError.new('pathspec must begin with "/" or "//"') end end
Public Instance Methods
==(other)
click to toggle source
# File lib/threatinator/parsers/xml/pattern.rb, line 47 def ==(other) _internal_data == other._internal_data end
_internal_data()
click to toggle source
# File lib/threatinator/parsers/xml/pattern.rb, line 43 def _internal_data [@path, @anchored] end
match?(path)
click to toggle source
@param [Threatinator::Parsers::XML::Path] path @return [Boolean] true if the pattern matches, false otherwise.
# File lib/threatinator/parsers/xml/pattern.rb, line 35 def match?(path) if @anchored == true @path == path else path.end_with?(@path) end end
max_depth()
click to toggle source
# File lib/threatinator/parsers/xml/pattern.rb, line 29 def max_depth @anchored == true ? @path.length : Float::INFINITY end