Class: Chromedriver::Helper::GoogleCodeParser

Inherits:
Object
  • Object
show all
Defined in:
lib/chromedriver/helper/google_code_parser.rb

Constant Summary collapse

BUCKET_URL =
'https://chromedriver.storage.googleapis.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform, open_uri_provider = OpenURI) ⇒ GoogleCodeParser

Returns a new instance of GoogleCodeParser.



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

def initialize(platform, open_uri_provider=OpenURI)
  @platform = platform
  @source = open_uri_provider.open_uri(BUCKET_URL)
end

Instance Attribute Details

#platformObject (readonly)

Returns the value of attribute platform.



9
10
11
# File 'lib/chromedriver/helper/google_code_parser.rb', line 9

def platform
  @platform
end

#sourceObject (readonly)

Returns the value of attribute source.



9
10
11
# File 'lib/chromedriver/helper/google_code_parser.rb', line 9

def source
  @source
end

Instance Method Details

#downloadsObject



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

def downloads
  @downloads ||= begin
    doc = Nokogiri::XML.parse(source)
    items = doc.css("Contents Key").collect {|k| k.text }
    items.reject! {|k| !(/chromedriver_#{platform}/===k) }
    items.map {|k| "#{BUCKET_URL}/#{k}"}
  end
end

#newest_download_versionObject



25
26
27
# File 'lib/chromedriver/helper/google_code_parser.rb', line 25

def newest_download_version
  @newest_download_version ||= downloads.map { |download| version_of(download) }.max
end

#version_download_url(version) ⇒ Object



29
30
31
32
# File 'lib/chromedriver/helper/google_code_parser.rb', line 29

def version_download_url(version)
  gem_version = Gem::Version.new(version)
  downloads.find { |download_url| version_of(download_url) == gem_version }
end