Class: WhatWeb::Matcher::Base

Inherits:
Object
  • #Object
show all
Defined in:
lib/whatweb/matcher/base.rb

Direct Known Subclasses

Common, GHDB, MD5, Status, TagPattern, Text, URL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, match) ⇒ Base

Returns a new instance of Base.



7
8
9
10
# File 'lib/whatweb/matcher/base.rb', line 7

def initialize(target, match)
  @target = target
  @match = match
end

Instance Attribute Details

#matchObject (readonly)

Returns the value of attribute match.



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

def match
  @match
end

#targetObject (readonly)

Returns the value of attribute target.



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

def target
  @target
end

Class Method Details

.match?(target, match) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/whatweb/matcher/base.rb', line 39

def self.match?(target, match)
  new(target, match).match?
end

Instance Method Details

#compiled_regexpObject

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/whatweb/matcher/base.rb', line 35

def compiled_regexp
  raise NotImplementedError, "You must implement #{self.class}##{__method__}"
end

#match?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/whatweb/matcher/base.rb', line 12

def match?
  compiled_regexp.match? search_context
rescue NoHeaderError => _
  false
end

#search_contextObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/whatweb/matcher/base.rb', line 18

def search_context
  search = match[:search]
  context = target.body
  case search
  when "all"
    context = target.raw_response
  when "header"
    context = target.raw_headers
  when /headers\[(.*)\]/
    k = $1.downcase
    header = target.headers[k]
    raise NoHeaderError, "There is no #{k} header in the response" unless header
    context = header
  end
  context.to_s
end