class MyManga::CLI::Commands::Mark

See desc

Public Instance Methods

call(flag:, names: nil, **options) click to toggle source
# File lib/my_manga/mark.rb, line 22
def call(flag:, names: nil, **options)
  names = manga_names(names)
  if options[:list]
    numbers = options[:list].to_s.split(',').map(&:strip)
    output ||= numbers.join(', ')
  elsif options[:to]
    numbers = (options.fetch(:from)..options.fetch(:to)).to_a
    output = [numbers.first, numbers.last].join('-')
  end
  output ||= '(all)'

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

    next unless count.positive?

    mark(manga, flag, chapters)
    print %(Chapters #{output} from "#{name}" )
    puts %(Marked as #{flag.capitalize})
  end
end
mark(manga, flag, chapters) click to toggle source
# File lib/my_manga/mark.rb, line 46
def mark(manga, flag, chapters)
  if flag == 'read'
    MyManga.read!(manga, chapters)
  else
    MyManga.unread!(manga, chapters)
  end
end