Class: EPUBInfo::Models::Book
- Inherits:
-
Object
- Object
- EPUBInfo::Models::Book
- Defined in:
- lib/epubinfo/models/book.rb
Instance Attribute Summary collapse
-
#contributors ⇒ Array
Contributors, array of Person instances (EPUB2 reference).
-
#cover ⇒ Cover
Cover.
-
#creators ⇒ Array
Creators, array of Person instances (EPUB2 reference).
-
#dates ⇒ Array
Dates, array of Date instances (EPUB2 reference).
-
#description ⇒ String
Description (EPUB2 reference).
-
#drm_protected ⇒ Boolean
(also: #drm_protected?)
DRM protected.
-
#identifiers ⇒ Array
Identifiers, array of Identifier instances (EPUB2 reference).
-
#languages ⇒ Array
Languages, array of String instances (EPUB2 reference).
-
#publisher ⇒ String
Publisher (EPUB2 reference).
-
#rights ⇒ String
Rights (EPUB2 reference).
-
#source ⇒ String
Source (EPUB2 reference).
-
#subjects ⇒ Array
Subjects, array of String instances (EPUB2 reference).
-
#titles ⇒ Array
Titles, array of String instances (EPUB2 reference).
-
#version ⇒ String
EPUB Version (http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section1.4.1.2).
Instance Method Summary collapse
-
#initialize(parser) ⇒ Book
constructor
Should never be called directly, go through EPUBInfo.get.
-
#to_hash ⇒ Hash
Returns Hash representation of the book.
Constructor Details
#initialize(parser) ⇒ Book
Should never be called directly, go through EPUBInfo.get
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/epubinfo/models/book.rb', line 70 def initialize(parser) document = parser. return if document.nil? document.remove_namespaces! = document.css('metadata') self.version = document.css('package')[0]['version'] self.titles = .xpath('.//title').map(&:content) self.creators = .xpath('.//creator').map {|c| EPUBInfo::Models::Person.new(c) } self.subjects = .xpath('.//subject').map(&:content) self.description = .xpath('.//description').first.content rescue nil self.publisher = .xpath('.//publisher').first.content rescue nil self.contributors = .xpath('.//contributor').map {|c| EPUBInfo::Models::Person.new(c) } self.dates = .xpath('.//date').map { |d| EPUBInfo::Models::Date.new(d) } modified_date = .xpath(".//meta[@property='dcterms:modified']").map do |d| date = EPUBInfo::Models::Date.new(d) date.event = 'modification' date end self.dates += modified_date; self.identifiers = .xpath('.//identifier').map { |i| EPUBInfo::Models::Identifier.new(i) } self.source = .xpath('.//source').first.content rescue nil self.languages = .xpath('.//language').map(&:content) self.rights = .xpath('.//rights').first.content rescue nil self.drm_protected = parser.drm_protected? self.cover = EPUBInfo::Models::Cover.new(parser) end |
Instance Attribute Details
#contributors ⇒ Array
Contributors, array of Person instances (EPUB2 reference)
29 30 31 |
# File 'lib/epubinfo/models/book.rb', line 29 def contributors @contributors end |
#creators ⇒ Array
Creators, array of Person instances (EPUB2 reference)
11 12 13 |
# File 'lib/epubinfo/models/book.rb', line 11 def creators @creators end |
#dates ⇒ Array
Dates, array of Date instances (EPUB2 reference)
34 35 36 |
# File 'lib/epubinfo/models/book.rb', line 34 def dates @dates end |
#description ⇒ String
Description (EPUB2 reference)
21 22 23 |
# File 'lib/epubinfo/models/book.rb', line 21 def description @description end |
#drm_protected ⇒ Boolean Also known as: drm_protected?
DRM protected
57 58 59 |
# File 'lib/epubinfo/models/book.rb', line 57 def drm_protected @drm_protected end |
#identifiers ⇒ Array
Identifiers, array of Identifier instances (EPUB2 reference)
39 40 41 |
# File 'lib/epubinfo/models/book.rb', line 39 def identifiers @identifiers end |
#languages ⇒ Array
Languages, array of String instances (EPUB2 reference)
48 49 50 |
# File 'lib/epubinfo/models/book.rb', line 48 def languages @languages end |
#publisher ⇒ String
Publisher (EPUB2 reference)
25 26 27 |
# File 'lib/epubinfo/models/book.rb', line 25 def publisher @publisher end |
#rights ⇒ String
Rights (EPUB2 reference)
53 54 55 |
# File 'lib/epubinfo/models/book.rb', line 53 def rights @rights end |
#source ⇒ String
Source (EPUB2 reference)
44 45 46 |
# File 'lib/epubinfo/models/book.rb', line 44 def source @source end |
#subjects ⇒ Array
Subjects, array of String instances (EPUB2 reference)
16 17 18 |
# File 'lib/epubinfo/models/book.rb', line 16 def subjects @subjects end |
#titles ⇒ Array
Titles, array of String instances (EPUB2 reference)
6 7 8 |
# File 'lib/epubinfo/models/book.rb', line 6 def titles @titles end |
#version ⇒ String
67 68 69 |
# File 'lib/epubinfo/models/book.rb', line 67 def version @version end |
Instance Method Details
#to_hash ⇒ Hash
Returns Hash representation of the book
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/epubinfo/models/book.rb', line 100 def to_hash { :titles => @titles, :creators => @creators.map(&:to_hash), :subjects => @subjects, :description => @description, :publisher => @publisher, :contributors => @contributors.map(&:to_hash), :dates => @dates.map(&:to_hash), :identifiers => @identifiers.map(&:to_hash), :source => @source, :languages => @languages, :rights => @rights, :drm_protected => @drm_protected, :cover => @cover, } end |