Class: WhatWeb::Matcher::Common

Inherits:
Base show all
Defined in:
lib/whatweb/matcher/common.rb

Instance Attribute Summary

Attributes inherited from Base

#match, #target

Instance Method Summary collapse

Methods inherited from Base

#initialize, match?, #search_context

Constructor Details

This class inherits a constructor from WhatWeb::Matcher::Base

Instance Method Details

#compiled_regexpObject



44
45
46
# File 'lib/whatweb/matcher/common.rb', line 44

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

#keyObject



6
7
8
# File 'lib/whatweb/matcher/common.rb', line 6

def key
  @key ||= keys.find { |k| match.key? k }
end

#keysObject



10
11
12
# File 'lib/whatweb/matcher/common.rb', line 10

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

#match?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
# File 'lib/whatweb/matcher/common.rb', line 27

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

#match_resultsObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/whatweb/matcher/common.rb', line 14

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

#offsetObject



40
41
42
# File 'lib/whatweb/matcher/common.rb', line 40

def offset
  match[:offset]
end

#offset?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/whatweb/matcher/common.rb', line 36

def offset?
  match[:offset]
end