Class: WebComics::CBZ

Inherits:
ComicsDir show all
Defined in:
lib/comics_cbz.rb

Direct Known Subclasses

ComicsEngine

Instance Attribute Summary collapse

Attributes inherited from ComicsDir

#series

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ComicsDir

comics_entries, #directory?, #file?, #filter_alpha_dirs, #filter_alphanum_dirs, #filter_num_dirs, #list_directories, #list_files, trim

Instance Attribute Details

#cbzObject

Returns the value of attribute cbz.



5
6
7
# File 'lib/comics_cbz.rb', line 5

def cbz
  @cbz
end

Class Method Details

.cbz_or_zip?(file) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
# File 'lib/comics_cbz.rb', line 7

def self.cbz_or_zip?(file)
  if File.extname(file) == ".cbz" || File.extname(file) == ".zip"
  	return true
  else
  	return false
  end
end

.ignore_xml(list) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/comics_cbz.rb', line 46

def self.ignore_xml(list)
  files_list = []
  list.each do |entry|
    files_list.push(entry) if File.extname(entry) != ".xml"
  end

  files_list
end

Instance Method Details

#extract(index = 0) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/comics_cbz.rb', line 37

def extract(index = 0)
  @page = nil
  Zip::File.open("#{@series}/#{@cbz}") do |cbz|
    @page = cbz.extract(list_pages_inside[index], list_pages_inside[index])
  end

  @page
end

#list_cbz_filesObject



15
16
17
18
19
20
21
22
# File 'lib/comics_cbz.rb', line 15

def list_cbz_files
  files_list = []
  list_files.each do |cbz|
    files_list.push(cbz) if CBZ.cbz_or_zip?(cbz)
  end

  files_list
end

#list_pages_inside(xml_ignore = true) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/comics_cbz.rb', line 24

def list_pages_inside(xml_ignore = true)
  files_list = []
  Zip::File.open("#{@series}/#{@cbz}") do |cbz|
    cbz.each do |pages|
      files_list.push(pages.name)
    end
  end

  return CBZ.ignore_xml(files_list) if xml_ignore

  files_list
end