Class: BrandEins::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/brandeins-dl.rb

Defined Under Namespace

Classes: ArchiveSite, PDFDownloader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Downloader

Returns a new instance of Downloader.



41
42
43
44
45
46
47
# File 'lib/brandeins-dl.rb', line 41

def initialize(path)
  @url     = 'http://www.brandeins.de'
  @archive = false
  @dl_dir  = path
  @tmp_dir = path + '/tmp'
  create_tmp_dirs
end

Instance Attribute Details

#archiveObject (readonly)

Returns the value of attribute archive.



39
40
41
# File 'lib/brandeins-dl.rb', line 39

def archive
  @archive
end

Instance Method Details

#get_magazine(year = 2000, volume = 1) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/brandeins-dl.rb', line 64

def get_magazine(year = 2000, volume = 1)
  setup
  puts "Parsing Volume #{volume} of #{year}"
  target_pdf = get_target_pdf(year, volume)

  magazine_links = @archive.get_magazine_links_by_year(year)
  target_magazine_link = magazine_links[volume-1]

  get_magazine_by_link(target_magazine_link, target_pdf)
end

#get_magazines_of_year(year = 2000) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/brandeins-dl.rb', line 53

def get_magazines_of_year(year = 2000)
  setup
  puts "Getting all brand eins magazines of a #{year}. This could take a while..."
  magazine_links_per_year = @archive.get_magazine_links_by_year(year)
  magazine_links_per_year.each_with_index do |magazine_link, volume|
    puts "Parsing Volume #{volume} of #{year}"
    target_pdf = get_target_pdf(year, volume)
    get_magazine_by_link(magazine_link, target_pdf)
  end
end

#setupObject



49
50
51
# File 'lib/brandeins-dl.rb', line 49

def setup
  @archive = ArchiveSite.new @url
end