Class: Apt::Spy2::Launchpad

Inherits:
Object
  • Object
show all
Defined in:
lib/apt/spy2/launchpad.rb

Overview

parse launchpad output

Instance Method Summary collapse

Constructor Details

#initialize(download) ⇒ Launchpad

Returns a new instance of Launchpad.



9
10
11
# File 'lib/apt/spy2/launchpad.rb', line 9

def initialize(download)
  @launchpad = download
end

Instance Method Details

#mirrors(country) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/apt/spy2/launchpad.rb', line 13

def mirrors(country)
  mirrors = []

  document = Nokogiri::HTML(@launchpad)
  table_rows = document.xpath("//tr/th[text()='#{country}']/../following-sibling::*")
  raise "Couldn't find a mirror for #{country}." if table_rows.empty?

  table_rows.each do |node|
    break if node['class'] == 'head' # this is the next country heading

    next if node.xpath(".//span[@class='distromirrorstatusUP']").empty? # this mirror is broken, behind, etc.

    # return all mirrors: .//a[not(starts-with(@href, '/'))] - we'll just get http(s):// for now
    node.xpath(".//a[starts-with(@href, 'http')]").each do |child|
      mirrors << child['href']
    end
  end

  mirrors
end