Class: Recog::Matcher
- Inherits:
-
Object
- Object
- Recog::Matcher
- Defined in:
- lib/recog/matcher.rb
Instance Attribute Summary collapse
-
#fingerprints ⇒ Object
readonly
Returns the value of attribute fingerprints.
-
#multi_match ⇒ Object
readonly
Returns the value of attribute multi_match.
-
#reporter ⇒ Object
readonly
Returns the value of attribute reporter.
Instance Method Summary collapse
-
#initialize(fingerprints, reporter, multi_match) ⇒ Matcher
constructor
A new instance of Matcher.
- #match_banners(banners_file) ⇒ Object
Constructor Details
#initialize(fingerprints, reporter, multi_match) ⇒ Matcher
Returns a new instance of Matcher.
10 11 12 13 14 |
# File 'lib/recog/matcher.rb', line 10 def initialize(fingerprints, reporter, multi_match) @fingerprints = fingerprints @reporter = reporter @multi_match = multi_match end |
Instance Attribute Details
#fingerprints ⇒ Object (readonly)
Returns the value of attribute fingerprints.
5 6 7 |
# File 'lib/recog/matcher.rb', line 5 def fingerprints @fingerprints end |
#multi_match ⇒ Object (readonly)
Returns the value of attribute multi_match.
5 6 7 |
# File 'lib/recog/matcher.rb', line 5 def multi_match @multi_match end |
#reporter ⇒ Object (readonly)
Returns the value of attribute reporter.
5 6 7 |
# File 'lib/recog/matcher.rb', line 5 def reporter @reporter end |
Instance Method Details
#match_banners(banners_file) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 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 55 |
# File 'lib/recog/matcher.rb', line 17 def () reporter.report do fd = $stdin file_source = false if && ( != '-') fd = File.open(, 'rb') file_source = true end fd.each_line do |line| reporter.increment_line_count line = line.to_s.unpack('C*').pack('C*').strip.gsub(/\\[rn]/, '') found_extractions = false extraction_data = [] fingerprints.each do |fp| extractions = fp.match(line) next unless extractions found_extractions = true extractions['data'] = line extraction_data << extractions break unless multi_match end if found_extractions reporter.match extraction_data else reporter.failure line end break if reporter.stop? end fd.close if file_source end end |