Class: Recog::DB
- Inherits:
-
Object
- Object
- Recog::DB
- Defined in:
- lib/recog/db.rb
Overview
A collection of fingerprints for matching against a particular
kind of fingerprintable data, e.g. an HTTP Server
header
Instance Attribute Summary collapse
-
#fingerprints ⇒ Array<Fingerprint>
readonly
Fingerprint objects that can be matched against strings that make sense for the #match_key.
-
#match_key ⇒ String
readonly
Taken from the
fingerprints/matches
element, or defaults to the basename of #path without the.xml
extension. - #path ⇒ String readonly
Instance Method Summary collapse
-
#initialize(path) ⇒ DB
constructor
A new instance of DB.
- #parse_fingerprints ⇒ void
Constructor Details
#initialize(path) ⇒ DB
Returns a new instance of DB.
21 22 23 24 25 26 27 |
# File 'lib/recog/db.rb', line 21 def initialize(path) @match_key = nil @path = path @fingerprints = [] parse_fingerprints end |
Instance Attribute Details
#fingerprints ⇒ Array<Fingerprint> (readonly)
Returns Fingerprint objects that can be matched against strings that make sense for the #match_key.
14 15 16 |
# File 'lib/recog/db.rb', line 14 def fingerprints @fingerprints end |
#match_key ⇒ String (readonly)
Returns Taken from the fingerprints/matches
element, or
defaults to the basename of #path without the .xml
extension.
18 19 20 |
# File 'lib/recog/db.rb', line 18 def match_key @match_key end |
#path ⇒ String (readonly)
10 11 12 |
# File 'lib/recog/db.rb', line 10 def path @path end |
Instance Method Details
#parse_fingerprints ⇒ void
This method returns an undefined value.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# 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 |