Class: Epub::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/epub-reader/reader.rb,
lib/epub-reader/version.rb

Constant Summary collapse

EPUB_MIMETYPE =
"application/epub+zip"
PACKAGE_MEDIATYPE =
"application/oebps-package+xml"
VERSION =
"0.0.9"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(f) ⇒ Reader

Returns a new instance of Reader.

Raises:



9
10
11
12
13
14
# File 'lib/epub-reader/reader.rb', line 9

def initialize(f)
  raise(FileNotFoundError, "File not found") unless File.exists?(f)
  @filepath  = f.to_s
  @file      = EpubFile.new(f)
  raise(MalformedFileError, "Invalid EPUB file format") unless valid?
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



7
8
9
# File 'lib/epub-reader/reader.rb', line 7

def file
  @file
end

#filepathObject (readonly)

Returns the value of attribute filepath.



7
8
9
# File 'lib/epub-reader/reader.rb', line 7

def filepath
  @filepath
end

Class Method Details

.open(f) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/epub-reader/reader.rb', line 16

def Reader.open(f)
  reader = Reader.new(f)
  if block_given?
    yield reader
  else
    reader
  end
end

Instance Method Details

#authorObject



45
46
47
# File 'lib/epub-reader/reader.rb', line 45

def author
  @author ||= package.creator
end

#containerObject



65
66
67
# File 'lib/epub-reader/reader.rb', line 65

def container
  @container ||= Container.new(self)
end

#coverObject



69
70
71
# File 'lib/epub-reader/reader.rb', line 69

def cover
  @cover ||= package.cover
end

#epub_versionObject



33
34
35
# File 'lib/epub-reader/reader.rb', line 33

def epub_version
  @version ||= package.version
end

#languageObject



53
54
55
# File 'lib/epub-reader/reader.rb', line 53

def language
  @language ||= package.language
end

#mimetypeObject



25
26
27
28
29
30
31
# File 'lib/epub-reader/reader.rb', line 25

def mimetype
  @mimetype ||= begin
    file.get_input_stream('mimetype').read
  rescue
    nil
  end
end

#package(index = 0) ⇒ Object

Convenient method



90
91
92
# File 'lib/epub-reader/reader.rb', line 90

def package(index = 0)
  container.package(index)
end

#pagesObject



61
62
63
# File 'lib/epub-reader/reader.rb', line 61

def pages
  @pages ||= toc.pages
end

#publication_dateObject



49
50
51
# File 'lib/epub-reader/reader.rb', line 49

def publication_date
  @publication_date ||= package.date
end

#titleObject



41
42
43
# File 'lib/epub-reader/reader.rb', line 41

def title
  @title ||= package.title
end

#tocObject



57
58
59
# File 'lib/epub-reader/reader.rb', line 57

def toc
  @toc ||= Toc.new(package.toc, self)
end

#uidObject



37
38
39
# File 'lib/epub-reader/reader.rb', line 37

def uid
  @uid ||= package.identifier
end