Class: MtgDb::Downloaders::AllCardsStandardDownloader
- Inherits:
-
DownloaderBase
- Object
- DownloaderBase
- MtgDb::Downloaders::AllCardsStandardDownloader
- Defined in:
- lib/mtg_db/downloaders.rb
Overview
Downloads the entire collection of cards in ‘Standard’ format
Constant Summary collapse
- DEBUG =
true
- ALL_CARDS_URL =
'http://gatherer.wizards.com/Pages/Search/Default.aspx?action=advanced&output=standard&special=true&cmc=|%3E=[0]'
Constants inherited from DownloaderBase
DownloaderBase::DEFAULT_OUTPUT_DIR
Instance Attribute Summary
Attributes inherited from DownloaderBase
Instance Method Summary collapse
Methods inherited from DownloaderBase
#initialize, #is_empty?, #prepare_output_dir
Constructor Details
This class inherits a constructor from MtgDb::Downloaders::DownloaderBase
Instance Method Details
#files ⇒ Object
60 61 62 |
# File 'lib/mtg_db/downloaders.rb', line 60 def files Dir.glob(File.join(@output_dir, 'page.*.html')).sort end |
#start ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 |