Class: MyManga::CLI::Commands::Zine

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

Overview

See desc

Constant Summary collapse

TMP_DIR =
File.expand_path('../../tmp', __dir__)
RECOVERY_FILE =
File.expand_path('../../zine-recovery.yaml', __dir__)

Instance Method Summary collapse

Methods inherited from MyManga::CLI::Command

#manga_names, #pad

Instance Method Details

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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/my_manga/zine.rb', line 34

def call(names: nil, **options)
  names = manga_names(names)
  filename = options.fetch(:filename) { nil }
  size = options.fetch(:size).to_i

  if options[:add] && options[:remove]
    puts "--add and --remove are mutually exclusive"
    exit 1
  end

  if options[:recover] == false && File.exist?(RECOVERY_FILE)
    File.delete(RECOVERY_FILE)
  end

  if options[:add]
    MyManga.add_to_zine(names)
    puts %("#{names.join(', ')}" added to the zine!)
  elsif options[:remove]
    MyManga.remove_from_zine(names)
    puts %("#{names.join(', ')}" removed from the zine!)
  else
    publish(filename, size)
  end
end