Class: MtgDb::Downloaders::DownloaderBase
- Inherits:
-
Object
- Object
- MtgDb::Downloaders::DownloaderBase
- Defined in:
- lib/mtg_db/downloaders.rb
Overview
Base class for all downloaders
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_OUTPUT_DIR =
'output'
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#output_dir ⇒ Object
Returns the value of attribute output_dir.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ DownloaderBase
constructor
A new instance of DownloaderBase.
- #is_empty? ⇒ Boolean
- #prepare_output_dir ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ DownloaderBase
Returns a new instance of DownloaderBase.
12 13 14 15 16 17 18 |
# File 'lib/mtg_db/downloaders.rb', line 12 def initialize( = {}) @agent = Mechanize.new @agent.pluggable_parser.default = Mechanize::FileSaver @output_dir = [:output_dir] || DEFAULT_OUTPUT_DIR prepare_output_dir end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
9 10 11 |
# File 'lib/mtg_db/downloaders.rb', line 9 def agent @agent end |
#output_dir ⇒ Object
Returns the value of attribute output_dir.
10 11 12 |
# File 'lib/mtg_db/downloaders.rb', line 10 def output_dir @output_dir end |
Instance Method Details
#is_empty? ⇒ Boolean
26 27 28 29 |
# File 'lib/mtg_db/downloaders.rb', line 26 def is_empty? html_files = File.join(@output_dir, '*.html') Dir.glob(html_files).empty? end |
#prepare_output_dir ⇒ Object
20 21 22 23 24 |
# File 'lib/mtg_db/downloaders.rb', line 20 def prepare_output_dir unless @output_dir.nil? || Dir.exist?(@output_dir) FileUtils.mkpath @output_dir end end |
#start ⇒ Object
31 32 33 |
# File 'lib/mtg_db/downloaders.rb', line 31 def start raise NotImplementedError end |