Class: ComicBook::CBT

Inherits:
Adapter show all
Defined in:
lib/comic_book/cbt.rb,
lib/comic_book/cbt/archiver.rb,
lib/comic_book/cbt/extractor.rb

Defined Under Namespace

Classes: Archiver, Extractor

Instance Method Summary collapse

Methods inherited from Adapter

#initialize

Constructor Details

This class inherits a constructor from ComicBook::Adapter

Instance Method Details

#archive(options = {}) ⇒ Object



9
10
11
# File 'lib/comic_book/cbt.rb', line 9

def archive options = {}
  Archiver.new(path).archive options
end

#extract(options = {}) ⇒ Object



13
14
15
# File 'lib/comic_book/cbt.rb', line 13

def extract options = {}
  Extractor.new(path).extract options
end

#infoObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/comic_book/cbt.rb', line 17

def info
  xml = nil

  File.open(path, 'rb') do |file|
    Gem::Package::TarReader.new(file) do |reader|
      reader.each do |entry|
        next unless entry.full_name == 'ComicInfo.xml'

        xml = entry.read
        break
      end
    end
  end

  return nil unless xml

  ComicInfo.load xml
end

#pagesObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/comic_book/cbt.rb', line 36

def pages
  entries = []

  File.open(path, 'rb') do |file|
    Gem::Package::TarReader.new(file) do |reader|
      reader.each do |entry|
        entries << entry.full_name if entry.file?
      end
    end
  end

  entries.select { image_file? it }
         .map    { create_page_from_entry it }
         .sort_by(&:name)
end