Class: EPUBInfo::Models::Book
- Inherits:
-
Object
- Object
- EPUBInfo::Models::Book
- Defined in:
- lib/epubinfo/models/book.rb
Instance Attribute Summary (collapse)
-
- (Array) contributors
Contributors, array of Person instances (EPUB2 reference).
-
- (Cover) cover
Cover.
-
- (Array) creators
Creators, array of Person instances (EPUB2 reference).
-
- (Array) dates
Dates, array of Date instances (EPUB2 reference).
-
- (String) description
Description (EPUB2 reference).
-
- (Boolean) drm_protected
(also: #drm_protected?)
DRM protected.
-
- (Array) identifiers
Identifiers, array of Identifier instances (EPUB2 reference).
-
- (Array) languages
Languages, array of String instances (EPUB2 reference).
-
- (String) publisher
Publisher (EPUB2 reference).
-
- (String) rights
Rights (EPUB2 reference).
-
- (String) source
Source (EPUB2 reference).
-
- (Array) subjects
Subjects, array of String instances (EPUB2 reference).
-
- (Array) titles
Titles, array of String instances (EPUB2 reference).
-
- (String) version
EPUB Version (http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section1.4.1.2).
Instance Method Summary (collapse)
-
- (Book) initialize(parser)
constructor
Should never be called directly, go through EPUBInfo.get.
-
- (Hash) to_hash
Returns Hash representation of the book.
Constructor Details
- (Book) initialize(parser)
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
- (Array) contributors
Contributors, array of Person instances (EPUB2 reference)
29 30 31 |
# File 'lib/epubinfo/models/book.rb', line 29 def contributors @contributors end |
- (Array) creators
Creators, array of Person instances (EPUB2 reference)
11 12 13 |
# File 'lib/epubinfo/models/book.rb', line 11 def creators @creators end |
- (Array) dates
Dates, array of Date instances (EPUB2 reference)
34 35 36 |
# File 'lib/epubinfo/models/book.rb', line 34 def dates @dates end |
- (String) description
Description (EPUB2 reference)
21 22 23 |
# File 'lib/epubinfo/models/book.rb', line 21 def description @description end |
- (Boolean) drm_protected Also known as: drm_protected?
DRM protected
57 58 59 |
# File 'lib/epubinfo/models/book.rb', line 57 def drm_protected @drm_protected end |
- (Array) identifiers
Identifiers, array of Identifier instances (EPUB2 reference)
39 40 41 |
# File 'lib/epubinfo/models/book.rb', line 39 def identifiers @identifiers end |
- (Array) languages
Languages, array of String instances (EPUB2 reference)
48 49 50 |
# File 'lib/epubinfo/models/book.rb', line 48 def languages @languages end |
- (String) publisher
Publisher (EPUB2 reference)
25 26 27 |
# File 'lib/epubinfo/models/book.rb', line 25 def publisher @publisher end |
- (String) rights
Rights (EPUB2 reference)
53 54 55 |
# File 'lib/epubinfo/models/book.rb', line 53 def rights @rights end |
- (String) source
Source (EPUB2 reference)
44 45 46 |
# File 'lib/epubinfo/models/book.rb', line 44 def source @source end |
- (Array) subjects
Subjects, array of String instances (EPUB2 reference)
16 17 18 |
# File 'lib/epubinfo/models/book.rb', line 16 def subjects @subjects end |
- (Array) titles
Titles, array of String instances (EPUB2 reference)
6 7 8 |
# File 'lib/epubinfo/models/book.rb', line 6 def titles @titles end |
- (String) version
67 68 69 |
# File 'lib/epubinfo/models/book.rb', line 67 def version @version end |
Instance Method Details
- (Hash) to_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 |