Class: Webdrivers::PhantomJS

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



30
31
32
# File 'lib/webdrivers/phantomjs.rb', line 30

def base_url
  'https://bitbucket.org/ariya/phantomjs/downloads'
end

.current_versionObject



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

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

.downloadsObject



20
21
22
23
24
25
26
27
28
# File 'lib/webdrivers/phantomjs.rb', line 20

def downloads
  doc = Nokogiri::XML.parse(OpenURI.open_uri(base_url))
  items = doc.css(".execute").collect { |item| item["href"] }
  format_platform = platform.dup.gsub('32', '-i686').gsub('64', '-x86_64')
  items.select! { |item| item.include?(format_platform) }
  items.each_with_object({}) do |item, hash|
    hash[item[/-(\d+\.\d+\.\d+)-/, 1]] = "https://bitbucket.org#{item}"
  end
end

.extract_file(filename) ⇒ Object



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

def extract_file(filename)
  FileUtils.mv("#{platform_install_dir}/#{filename}/bin/#{file_name}", file_name)
end

.file_nameObject



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

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

.newest_versionObject



16
17
18
# File 'lib/webdrivers/phantomjs.rb', line 16

def newest_version
  downloads.keys.sort.last
end