Sha256: 9828addbb1c3978f1daf91744cae3f8619f5f2dafa3ef8a8105ceb13f3d8f240

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module WhatWeb
  module Matcher
    class Common < Base
      def key
        @key ||= keys.find { |k| match.key? k }
      end

      def keys
        %i[regexp account os module model string firmware filepath]
      end

      def match_results
        @match_results ||= [].tap do |out|
          regexp_matches = search_context.scan(compiled_regexp)
          out << regexp_matches.map do |regexp_match|
            if regexp_match.is_a?(Array)
              regexp_match[offset || 0]
            else
              regexp_match
            end
          end
        end.flatten.compact.sort.uniq
      end

      def match?
        return false unless match[key].class == Regexp
        begin
          !match_results.empty?
        rescue NoHeaderError => _
          false
        end
      end

      def offset?
        match[:offset]
      end

      def offset
        match[:offset]
      end

      def compiled_regexp
        match[key].class == Regexp ? match[key] : Regexp.new(Regexp.escape(match[key].to_s))
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
simple_whatweb-0.4.1 lib/whatweb/matcher/common.rb
simple_whatweb-0.4.0 lib/whatweb/matcher/common.rb
simple_whatweb-0.3.0 lib/whatweb/matcher/common.rb
simple_whatweb-0.2.1 lib/whatweb/matcher/common.rb
simple_whatweb-0.2.0 lib/whatweb/matcher/common.rb
simple_whatweb-0.1.0 lib/whatweb/matcher/common.rb