Class: MtgDb::Downloaders::DownloaderBase

Inherits:
Object
  • Object
show all
Defined in:
lib/mtg_db/downloaders.rb

Overview

Base class for all downloaders

Constant Summary collapse

DEFAULT_OUTPUT_DIR =
'output'

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @agent = Mechanize.new
  @agent.pluggable_parser.default = Mechanize::FileSaver
  @output_dir = options[:output_dir] || DEFAULT_OUTPUT_DIR

  prepare_output_dir
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



9
10
11
# File 'lib/mtg_db/downloaders.rb', line 9

def agent
  @agent
end

#output_dirObject

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

Returns:

  • (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_dirObject



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

#startObject

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/mtg_db/downloaders.rb', line 31

def start
  raise NotImplementedError
end