Class: WhatWeb::Matcher::Version

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name_product = nil, versions = nil, url = nil) ⇒ Version

Returns a new instance of Version.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/whatweb/matcher/version.rb', line 7

def initialize(name_product = nil, versions = nil, url = nil)
  raise ArgumentError, 'You must specify the name of the product' if name_product.nil?
  raise ArgumentError, 'You must specify the available versions of the product' if versions.nil?
  raise ArgumentError, 'You must specify the available url of the website' if url.nil?

  @name = name_product
  @versions = versions
  @files = { 'filenames' => [], 'files' => [], 'md5' => [] }
  @url = url
  @best_versions = []

  versions.each do |_version, value|
    # e.g. key => "5.0.0"
    # e.g. value => [["login.php", "59a69886a8c006d607369865f1b4a28c"]]]
    value.each do |filename, _md5|
      next if @files['filenames'].include? filename
      @files['filenames'] << filename

      url = URI.join(@url.to_s, filename.to_s)
      @files['files'] << url

      target = Target.new(url)
      @files['md5'] << target.md5sum
    end
  end
end

Instance Attribute Details

#best_versionsObject (readonly)

Returns the value of attribute best_versions.



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

def best_versions
  @best_versions
end

#filesObject (readonly)

Returns the value of attribute files.



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

def files
  @files
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

#versionsObject (readonly)

Returns the value of attribute versions.



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

def versions
  @versions
end

Instance Method Details

#best_matchObject



34
35
36
# File 'lib/whatweb/matcher/version.rb', line 34

def best_match
  versions.max { |x, y| x[1].length <=> y[1].length }
end

#matches_formatObject



38
39
40
41
42
# File 'lib/whatweb/matcher/version.rb', line 38

def matches_format
  return [] if versions.empty?
  version, _files = best_match
  [version]
end