class Apt::Spy2::Launchpad

parse launchpad output

Public Class Methods

new(download) click to toggle source
# File lib/apt/spy2/launchpad.rb, line 9
def initialize(download)
  @launchpad = download
end

Public Instance Methods

mirrors(country) click to toggle source
# 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