Class: Webdrivers::Geckodriver

Inherits:
Common
  • Object
show all
Defined in:
lib/webdrivers/geckodriver.rb

Class Method Summary collapse

Methods inherited from Common

binary_path, decompress_file, download, download_url, install, install_dir, internet_connection?, platform, platform_install_dir, untargz_file, unzip_file

Class Method Details

.base_urlObject



35
36
37
# File 'lib/webdrivers/geckodriver.rb', line 35

def base_url
  'https://github.com/mozilla/geckodriver/releases'
end

.current_versionObject



11
12
13
14
# File 'lib/webdrivers/geckodriver.rb', line 11

def current_version
  return nil unless File.exists?(binary_path)
  %x(#{binary_path} --version).match(/geckodriver (\d\.\d+\.\d+)/)[1]
end

.downloadsObject



25
26
27
28
29
30
31
32
33
# File 'lib/webdrivers/geckodriver.rb', line 25

def downloads
  doc = Nokogiri::XML.parse(OpenURI.open_uri(base_url))
  items = doc.css(".release-downloads a").collect {|item| item["href"]}
  items.reject! {|item| item.include?('archive')}
  items.select! {|item| item.include?(platform)}
  items.each_with_object({}) do |item, hash|
    hash[item[/v(\d+\.\d+\.\d+)/, 1]] = "https://github.com#{item}"
  end
end

.file_nameObject



7
8
9
# File 'lib/webdrivers/geckodriver.rb', line 7

def file_name
  platform == "win" ? "geckodriver.exe" : "geckodriver"
end

.newest_versionObject



16
17
18
19
20
21
22
23
# File 'lib/webdrivers/geckodriver.rb', line 16

def newest_version
  padded = downloads.keys.each_with_object({}) do |version, hash|
    matched = version.match(/^(\d+)\.(\d+)\.(\d+)$/)
    minor = sprintf '%02d', matched[2]
    hash["#{matched[1]}.#{minor}.#{matched[3]}"] = version
  end
  padded.keys.sort.last
end