Class: ComicBook
- Inherits:
-
Object
- Object
- ComicBook
- Defined in:
- lib/comic_book/adapter.rb,
lib/comicbook.rb,
lib/comic_book/cb.rb,
lib/comic_book/cb7.rb,
lib/comic_book/cba.rb,
lib/comic_book/cbr.rb,
lib/comic_book/cbt.rb,
lib/comic_book/cbz.rb,
lib/comic_book/cli.rb,
lib/comic_book/pdf.rb,
lib/comic_book/page.rb,
lib/comic_book/entry.rb,
lib/comic_book/version.rb,
lib/comic_book/cb/archiver.rb,
lib/comic_book/cli_helpers.rb,
lib/comic_book/cb/extractor.rb,
lib/comic_book/cb7/archiver.rb,
lib/comic_book/cbt/archiver.rb,
lib/comic_book/cbz/archiver.rb,
lib/comic_book/cb7/extractor.rb,
lib/comic_book/cbr/extractor.rb,
lib/comic_book/cbt/extractor.rb,
lib/comic_book/cbz/extractor.rb,
lib/comic_book/pdf/extractor.rb
Overview
NOTE: don’t use ComicBook::Adapter.new directly
Inherit from it when making an adapter to formats:
.cb .cb7 .cba .cbr .cbt .cbz .pdf
Defined Under Namespace
Classes: Adapter, CB, CB7, CBA, CBR, CBT, CBZ, CLI, CLIHelpers, Entry, Error, PDF, Page
Constant Summary collapse
- Info =
ComicInfo::Issue
- IMAGE_EXTENSIONS =
%w[.jpg .jpeg .png .gif .bmp .webp].freeze
- IMAGE_GLOB_PATTERN =
'*.{jpg,jpeg,png,gif,bmp,webp}'.freeze
- INFO_FILENAMES =
Metadata sidecar files (used by the :images_and_info file selection).
%w[ComicInfo.xml MetronInfo.xml].freeze
- VERSION =
'0.4.0'.freeze
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #archive(options = {}) ⇒ Object
- #extract(options = {}) ⇒ Object
-
#files(type: :all) ⇒ Object
The files in this comicbook, filtered by type: :all (default), :images, :images_and_info (images + ComicInfo.xml / MetronInfo.xml).
- #info ⇒ Object
-
#initialize(path) ⇒ ComicBook
constructor
A new instance of ComicBook.
-
#pages ⇒ Object
Pages are the image files, in path order, wrapped as Page objects.
Constructor Details
#initialize(path) ⇒ ComicBook
Returns a new instance of ComicBook.
26 27 28 29 30 |
# File 'lib/comicbook.rb', line 26 def initialize path @path = File. path.strip @type = determine_type path validate_path! end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
24 25 26 |
# File 'lib/comicbook.rb', line 24 def path @path end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
24 25 26 |
# File 'lib/comicbook.rb', line 24 def type @type end |
Class Method Details
.archive(path, options = {}) ⇒ Object
36 37 38 |
# File 'lib/comicbook.rb', line 36 def self.archive path, = {} new(path).archive end |
.extract(path, options = {}) ⇒ Object
40 41 42 |
# File 'lib/comicbook.rb', line 40 def self.extract path, = {} new(path).extract end |
.load(path) ⇒ Object
32 33 34 |
# File 'lib/comicbook.rb', line 32 def self.load path new path end |
Instance Method Details
#archive(options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/comicbook.rb', line 44 def archive = {} raise Error, 'Cannot archive a file' unless %i[folder cb].include?(type) output_format = [:to] ? File.extname([:to]).downcase : '.cbz' case output_format when '.cb' then CB.new(path).archive when '.cb7' then CB7.new(path).archive when '.cbt' then CBT.new(path).archive when '.cbz' then CBZ.new(path).archive else raise Error, "Unsupported archive format: #{output_format}" end end |
#extract(options = {}) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/comicbook.rb', line 59 def extract = {} raise Error, 'Cannot extract a folder' if type == :folder raise Error, '.cb folders are already extracted (they are uncompressed folders)' if type == :cb adapter.extract end |
#files(type: :all) ⇒ Object
The files in this comicbook, filtered by type:
:all (default),
:images,
:images_and_info (images + ComicInfo.xml / MetronInfo.xml)
72 73 74 |
# File 'lib/comicbook.rb', line 72 def files type: :all filter_files adapter.entries, by: type end |
#info ⇒ Object
66 |
# File 'lib/comicbook.rb', line 66 def info = adapter.info |
#pages ⇒ Object
Pages are the image files, in path order, wrapped as Page objects. PDF renders synthetic pages and CBA is a stub, so both stay custom.
78 79 80 81 82 |
# File 'lib/comicbook.rb', line 78 def pages return adapter.pages if %i[cba pdf].include?(type) files(type: :images).map { Page.new it.path, it.name } end |