Class: EPUBMeta::Models::Book
- Inherits:
-
Object
- Object
- EPUBMeta::Models::Book
- Defined in:
- lib/epubmeta/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.
-
#fixed_layout ⇒ Boolean
(also: #fixed_layout?)
Fixed layout.
-
#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 EPUBMeta.get.
-
#to_hash ⇒ Hash
Returns Hash representation of the book.
Constructor Details
#initialize(parser) ⇒ Book
Should never be called directly, go through EPUBMeta.get
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/epubmeta/models/book.rb', line 76 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| EPUBMeta::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| EPUBMeta::Models::Person.new(c) } self.dates = .xpath('.//date').map { |d| EPUBMeta::Models::Date.new(d) } modified_date = .xpath(".//meta[@property='dcterms:modified']").map do |d| date = EPUBMeta::Models::Date.new(d) date.event = 'modification' date end self.dates += modified_date; self.identifiers = .xpath('.//identifier').map { |i| EPUBMeta::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 = EPUBMeta::Models::Cover.new(parser) rendition_element = .xpath(".//meta[@property='rendition:layout']").first if rendition_element.nil? self.fixed_layout = false else self.fixed_layout = rendition_element.content == "pre-paginated" end end |
Instance Attribute Details
#contributors ⇒ Array
Contributors, array of Person instances (EPUB2 reference)
29 30 31 |
# File 'lib/epubmeta/models/book.rb', line 29 def contributors @contributors end |
#creators ⇒ Array
Creators, array of Person instances (EPUB2 reference)
11 12 13 |
# File 'lib/epubmeta/models/book.rb', line 11 def creators @creators end |
#dates ⇒ Array
Dates, array of Date instances (EPUB2 reference)
34 35 36 |
# File 'lib/epubmeta/models/book.rb', line 34 def dates @dates end |
#description ⇒ String
Description (EPUB2 reference)
21 22 23 |
# File 'lib/epubmeta/models/book.rb', line 21 def description @description end |
#drm_protected ⇒ Boolean Also known as: drm_protected?
DRM protected
63 64 65 |
# File 'lib/epubmeta/models/book.rb', line 63 def drm_protected @drm_protected end |
#fixed_layout ⇒ Boolean Also known as: fixed_layout?
Fixed layout
44 45 46 |
# File 'lib/epubmeta/models/book.rb', line 44 def fixed_layout @fixed_layout end |
#identifiers ⇒ Array
Identifiers, array of Identifier instances (EPUB2 reference)
39 40 41 |
# File 'lib/epubmeta/models/book.rb', line 39 def identifiers @identifiers end |
#languages ⇒ Array
Languages, array of String instances (EPUB2 reference)
54 55 56 |
# File 'lib/epubmeta/models/book.rb', line 54 def languages @languages end |
#publisher ⇒ String
Publisher (EPUB2 reference)
25 26 27 |
# File 'lib/epubmeta/models/book.rb', line 25 def publisher @publisher end |
#rights ⇒ String
Rights (EPUB2 reference)
59 60 61 |
# File 'lib/epubmeta/models/book.rb', line 59 def rights @rights end |
#source ⇒ String
Source (EPUB2 reference)
50 51 52 |
# File 'lib/epubmeta/models/book.rb', line 50 def source @source end |
#subjects ⇒ Array
Subjects, array of String instances (EPUB2 reference)
16 17 18 |
# File 'lib/epubmeta/models/book.rb', line 16 def subjects @subjects end |
#titles ⇒ Array
Titles, array of String instances (EPUB2 reference)
6 7 8 |
# File 'lib/epubmeta/models/book.rb', line 6 def titles @titles end |
#version ⇒ String
73 74 75 |
# File 'lib/epubmeta/models/book.rb', line 73 def version @version end |
Instance Method Details
#to_hash ⇒ Hash
Returns Hash representation of the book
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/epubmeta/models/book.rb', line 113 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, :fixed_layout => @fixed_layout, :cover => @cover, } end |