class EPUBMeta::Models::Book

Attributes

contributors[RW]

Contributors, array of Person instances ({idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.6 EPUB2 reference}) @return [Array]

cover[RW]

Cover @return [Cover]

creators[RW]

Creators, array of Person instances ({idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.2 EPUB2 reference}) @return [Array]

dates[RW]

Dates, array of Date instances ({idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.7 EPUB2 reference}) @return [Array]

description[RW]

Description ({idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.4 EPUB2 reference}) @return [String]

drm_protected[RW]

DRM protected @return [Boolean]

drm_protected?[RW]

DRM protected @return [Boolean]

fixed_layout[RW]

Fixed layout @return [Boolean]

fixed_layout?[RW]

Fixed layout @return [Boolean]

identifiers[RW]

Identifiers, array of Identifier instances ({idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.10 EPUB2 reference}) @return [Array]

languages[RW]

Languages, array of String instances ({idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.12 EPUB2 reference}) @return [Array]

publisher[RW]

Publisher ({idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.5 EPUB2 reference}) @return [String]

rights[RW]

Rights ({idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.15 EPUB2 reference}) @return [String]

source[RW]

Source ({idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.11 EPUB2 reference}) @return [String]

subjects[RW]

Subjects, array of String instances ({idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.3 EPUB2 reference}) @return [Array]

titles[RW]

Titles, array of String instances ({idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.2.1 EPUB2 reference}) @return [Array]

version[RW]

Public Class Methods

new(parser) click to toggle source

Should never be called directly, go through EPUBMeta.get

# File lib/epubmeta/models/book.rb, line 76
def initialize(parser)
  document = parser.metadata_document
  return if document.nil?
  document.remove_namespaces!
  metadata = document.css('metadata')
  self.version = document.css('package')[0]['version']
  self.titles = metadata.xpath('.//title').map(&:content)
  self.creators = metadata.xpath('.//creator').map {|c| EPUBMeta::Models::Person.new(c) }
  self.subjects = metadata.xpath('.//subject').map(&:content)
  self.description = metadata.xpath('.//description').first.content rescue nil
  self.publisher = metadata.xpath('.//publisher').first.content rescue nil
  self.contributors = metadata.xpath('.//contributor').map {|c| EPUBMeta::Models::Person.new(c) }
  self.dates = metadata.xpath('.//date').map { |d| EPUBMeta::Models::Date.new(d) }
  modified_date = metadata.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 = metadata.xpath('.//identifier').map { |i| EPUBMeta::Models::Identifier.new(i) }
  self.source = metadata.xpath('.//source').first.content rescue nil
  self.languages = metadata.xpath('.//language').map(&:content)
  self.rights = metadata.xpath('.//rights').first.content rescue nil
  self.drm_protected = parser.drm_protected?
  self.cover = EPUBMeta::Models::Cover.new(parser)

  rendition_element = metadata.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

Public Instance Methods

to_hash() click to toggle source

Returns Hash representation of the book @return [Hash]

# 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