Sha256: d21410e97716320b76c968c488359a74941beb84f7251851ce4528deb03c34c5

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

module CMSScanner
  module Finders
    # 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
    class UniqueFinders < IndependentFinders
      # @param [ Hash ] opts
      # @option opts [ Symbol ] mode :mixed, :passive or :aggressive
      # @option opts [ Int ] :confidence_threshold  If a finding's confidence reaches this value,
      #                                             it will be returned as the best finding.
      #                                             Default is 100.
      #                                             If <= 0, all finders will be ran.
      #
      # @return [ Object ]
      def run(opts = {})
        opts[:confidence_threshold] ||= 100

        symbols_from_mode(opts[:mode]).each do |symbol|
          each do |finder|
            [*finder.send(symbol, opts)].each do |found|
              findings << found
            end

            next if opts[:confidence_threshold] <= 0

            findings.each do |f|
              return f if f.confidence >= opts[:confidence_threshold]
            end
          end
        end

        # results are sorted by confidence ASC
        findings.sort_by(&:confidence).last
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cms_scanner-0.0.12 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.11 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.10 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.9 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.8 lib/cms_scanner/finders/unique_finders.rb
cms_scanner-0.0.7 lib/cms_scanner/finders/unique_finders.rb