Class: Apt::Spy2::Launchpad
- Inherits:
-
Object
- Object
- Apt::Spy2::Launchpad
- Defined in:
- lib/apt/spy2/launchpad.rb
Instance Method Summary collapse
- #get_mirrors(country) ⇒ Object
-
#initialize(download) ⇒ Launchpad
constructor
A new instance of Launchpad.
Constructor Details
#initialize(download) ⇒ Launchpad
Returns a new instance of Launchpad.
7 8 9 |
# File 'lib/apt/spy2/launchpad.rb', line 7 def initialize(download) @launchpad = download end |
Instance Method Details
#get_mirrors(country) ⇒ Object
11 12 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 11 def get_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 return mirrors end |