class Mangdown::Chapter

Mangdown chapter object, which holds pages

Attributes

chapter[R]

Public Class Methods

new(chapter) click to toggle source
# File lib/mangdown/chapter.rb, line 16
def initialize(chapter)
  @chapter = chapter
end

Public Instance Methods

cbz(dir = to_path) click to toggle source
# File lib/mangdown/chapter.rb, line 40
def cbz(dir = to_path)
  CBZ.one(dir)
end
download_to(dir = nil, opts = { force_download: false }) click to toggle source

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/MethodLength rubocop:disable Metrics/PerceivedComplexity

# File lib/mangdown/chapter.rb, line 48
def download_to(dir = nil, opts = { force_download: false })
  failed = []
  succeeded = []
  skipped = []

  setup_download_dir!(dir)
  if opts[:force_download]
    FileUtils.rm_r(to_path)
    setup_download_dir!(dir)
  end

  Tools.hydra_streaming(
    pages,
    chapter.hydra_opts
  ) do |stage, page, data = nil|
    case stage
    when :failed
      failed << [page, data]
    when :succeeded
      succeeded << page
    when :before
      !(page.file_exist?(to_path) && skipped << page)
    when :body
      page.append_file_data(to_path, data) unless failed.include?(page)
    when :complete
      page.append_file_ext(to_path) unless failed.include?(page)
    end
  end

  FileUtils.rm_r(to_path) if succeeded.empty? && skipped.empty?

  { failed: failed, succeeded: succeeded, skipped: skipped }
end
manga() click to toggle source
# File lib/mangdown/chapter.rb, line 24
def manga
  @manga ||= Mangdown.manga(chapter.manga)
end
pages() click to toggle source
# File lib/mangdown/chapter.rb, line 20
def pages
  @pages ||= chapter.pages.map { |page| Mangdown.page(page) }
end
path() click to toggle source
# File lib/mangdown/chapter.rb, line 28
def path
  @path ||= setup_path
end
Also aliased as: to_path
setup_path(dir = nil) click to toggle source
# File lib/mangdown/chapter.rb, line 33
def setup_path(dir = nil)
  dir ||= manga.path
  path = Tools.file_join(dir, name)
  path = Tools.valid_path_name(path)
  @path = Tools.relative_or_absolute_path(path)
end
to_path()
Alias for: path

Private Instance Methods

setup_download_dir!(dir) click to toggle source

rubocop:enable Metrics/AbcSize rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/MethodLength rubocop:enable Metrics/PerceivedComplexity

# File lib/mangdown/chapter.rb, line 88
def setup_download_dir!(dir)
  setup_path(dir)
  FileUtils.mkdir_p(to_path) unless Dir.exist?(to_path)
end