class Recog::DB

A collection of {Fingerprint fingerprints} for matching against a particular kind of fingerprintable data, e.g. an HTTP `Server` header

Attributes

fingerprints[R]

@return [Array<Fingerprint>] {Fingerprint} objects that can be matched

against strings that make sense for the {#match_key}
match_key[R]

@return [String] Taken from the `fingerprints/matches` element, or

defaults to the basename of {#path} without the `.xml` extension.
path[R]

@return [String]

Public Class Methods

new(path) click to toggle source

@param path [String]

# File lib/recog/db.rb, line 21
def initialize(path)
  @match_key = nil
  @path = path
  @fingerprints = []

  parse_fingerprints
end

Public Instance Methods

parse_fingerprints() click to toggle source

@return [void]

# File lib/recog/db.rb, line 30
def parse_fingerprints
  xml = nil

  File.open(self.path, "rb") do |fd|
    xml = Nokogiri::XML(fd.read(fd.stat.size))
  end

  raise "#{self.path} is invalid XML: #{xml.errors.join(',')}" unless xml.errors.empty?

  xml.xpath("/fingerprints").each do |fbase|
    if fbase['matches']
      @match_key = fbase['matches'].to_s
    end
  end

  unless @match_key
    @match_key = File.basename(self.path).sub(/\.xml$/, '')
  end

  xml.xpath("/fingerprints/fingerprint").each do |fprint|
    @fingerprints << Fingerprint.new(fprint)
  end

  xml = nil
end