Class: CMSScanner::Finders::UniqueFinders
- Inherits:
-
IndependentFinders
- Object
- Array
- IndependentFinders
- CMSScanner::Finders::UniqueFinders
- Defined in:
- lib/cms_scanner/finders/unique_finders.rb
Overview
Unique Finders container
This class is designed to return a unique result such as a version Note: Finders contained can return multiple results but the #run will only returned the best finding
Instance Method Summary collapse
-
#best_finding(findings) ⇒ Object, false
The best finding or false if none.
-
#run(opts = {}) ⇒ Object, false
The best finding or false if none.
Methods inherited from IndependentFinders
Instance Method Details
#best_finding(findings) ⇒ Object, false
Returns The best finding or false if none.
38 39 40 41 42 43 44 45 46 |
# File 'lib/cms_scanner/finders/unique_finders.rb', line 38 def best_finding(findings) # results are sorted by confidence ASC findings.sort_by!(&:confidence) # If all findings have the same confidence, false is returned return false if findings.size > 1 && findings.first.confidence == findings.last.confidence findings.last || false end |
#run(opts = {}) ⇒ Object, false
Returns The best finding or false if none.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cms_scanner/finders/unique_finders.rb', line 17 def run(opts = {}) opts[:confidence_threshold] ||= 100 symbols_from_mode(opts[:mode]).each do |symbol| each do |finder| [*finder.send(symbol, opts.merge(found: findings))].compact.each do |found| findings << found end next if opts[:confidence_threshold] <= 0 findings.each { |f| return f if f.confidence >= opts[:confidence_threshold] } end end best_finding(findings) end |