class Threatinator::Parsers::XML::Path

Attributes

parts[R]

Public Class Methods

new(str_or_parts = nil) click to toggle source

@param [String, Array, nil] str_or_parts ([]) If set to a String, splits

the string by '/' into an array. If set to an Array, sets parts to a
duplicate of the array. If set to nil or not specified, defaults to 
a new array.

@raise [TypeError] if something other than a String, Array, or nil is

specified for str_or_parts.
# File lib/threatinator/parsers/xml/path.rb, line 13
def initialize(str_or_parts = nil)
  @parts = 
    case str_or_parts
    when ::String
      if str_or_parts.length == 0 or !str_or_parts.start_with?('/')
        raise ArgumentError.new('str_or_parts must be a String beginning with "/"')
      end
      r = str_or_parts.split('/')
      r.shift
      r
    when ::Array
      str_or_parts.dup
    when nil
      []
    else
      raise TypeError.new("Expected argument must be a String, Array, or nil")
    end
end

Public Instance Methods

==(other) click to toggle source
# File lib/threatinator/parsers/xml/path.rb, line 32
def ==(other)
  @parts == other.parts
end
end_with?(other_path) click to toggle source

length = 5

 0 1 2 3 4
/a/b/c/d/e
       0 1
      /d/e
# File lib/threatinator/parsers/xml/path.rb, line 46
def end_with?(other_path)
  return false if other_path.length > self.length
  return true if other_path.length == 0
  pos = length - other_path.length
  other_path.parts.each_with_index do |other_part, idx|
    return false unless @parts[(pos + idx)] == other_part
  end
  true
end
eql?(other) click to toggle source
# File lib/threatinator/parsers/xml/path.rb, line 36
def eql?(other)
  other.kind_of?(self.class) &&
    self == other
end
length() click to toggle source
# File lib/threatinator/parsers/xml/path.rb, line 64
def length
  @parts.length
end
pop() click to toggle source
# File lib/threatinator/parsers/xml/path.rb, line 60
def pop
  @parts.pop
end
push(name) click to toggle source
# File lib/threatinator/parsers/xml/path.rb, line 56
def push(name)
  @parts.push(name)
end