class MtgDb::Downloaders::AllCardsStandardDownloader

Downloads the entire collection of cards in 'Standard' format

Constants

ALL_CARDS_URL
DEBUG

Public Instance Methods

files() click to toggle source
# File lib/mtg_db/downloaders.rb, line 60
def files
  Dir.glob(File.join(@output_dir, 'page.*.html')).sort
end
start() click to toggle source
# File lib/mtg_db/downloaders.rb, line 41
def start
  page_num = 1
  page = @agent.get(ALL_CARDS_URL)
  last_page = false
  until last_page
    page_num_str = page_num.to_s.rjust(3, '0')
    save_filename = File.join(@output_dir, "page.#{page_num_str}.html")
    puts "Saving to #{save_filename}" if DEBUG
    page.save(save_filename)
    begin
      page = @agent.page.links.find { |l| l.text == ' >' }.click
    rescue NoMethodError
      # `find` returns nil when the link can't be found
      last_page = true
    end
    page_num += 1
  end
end