Class: MyManga::CLI::Commands::Download

Inherits:
MyManga::CLI::Command show all
Defined in:
lib/my_manga/download.rb

Overview

See desc

Instance Method Summary collapse

Methods inherited from MyManga::CLI::Command

#manga_names, #pad

Instance Method Details

#call(names: nil, **options) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/my_manga/download.rb', line 21

def call(names: nil, **options)
  names = manga_names(names)
  numbers = if options[:list]
              options[:list].to_s.split(',').map(&:strip)
            elsif options[:to]
              (options.fetch(:from)..options.fetch(:to)).to_a
            end

  names.each do |name|
    manga = MyManga[name]
    chapters = numbers || manga.chapters_unread_numbers
    count = chapters.length

    next unless count.positive?

    puts "Downloading #{count} Chapters from \"#{name}\""
    MyManga.download(manga, chapters)
  end

  puts '...'
  puts 'Finished Download!'
rescue Mangdown::Error => e
  puts "Failed to download: #{e.message}"
end