Class: Webdrivers::Chromedriver

Inherits:
Common
  • Object
show all
Defined in:
lib/webdrivers/chromedriver.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



34
35
36
# File 'lib/webdrivers/chromedriver.rb', line 34

def base_url
  'http://chromedriver.storage.googleapis.com'
end

.current_versionObject



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

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

.downloadsObject



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

def downloads
  doc = Nokogiri::XML.parse(OpenURI.open_uri(base_url))
  items = doc.css("Contents Key").collect(&:text)
  items.select! { |item| item.include?(platform) }
  items.each_with_object({}) do |item, hash|
    hash[item[/^[^\/]+/]] = "#{base_url}/#{item}"
  end
end

.file_nameObject



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

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

.newest_versionObject



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

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