Class: EPUBInfo::Models::Book

Inherits:
Object
  • Object
show all
Defined in:
lib/epubinfo/models/book.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ Book

Should never be called directly, go through EPUBInfo.get



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
# File 'lib/epubinfo/models/book.rb', line 80

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)
  self.table_of_contents = EPUBInfo::Models::TableOfContents.new(parser)
  self.type = .xpath('.//type').first.content rescue ''
end

Instance Attribute Details

#contributorsArray

Contributors, array of Person instances (EPUB2 reference)



29
30
31
# File 'lib/epubinfo/models/book.rb', line 29

def contributors
  @contributors
end

#coverCover

Cover



63
64
65
# File 'lib/epubinfo/models/book.rb', line 63

def cover
  @cover
end

#creatorsArray

Creators, array of Person instances (EPUB2 reference)



11
12
13
# File 'lib/epubinfo/models/book.rb', line 11

def creators
  @creators
end

#datesArray

Dates, array of Date instances (EPUB2 reference)



34
35
36
# File 'lib/epubinfo/models/book.rb', line 34

def dates
  @dates
end

#descriptionString

Description (EPUB2 reference)



21
22
23
# File 'lib/epubinfo/models/book.rb', line 21

def description
  @description
end

#drm_protectedBoolean Also known as: drm_protected?

DRM protected



57
58
59
# File 'lib/epubinfo/models/book.rb', line 57

def drm_protected
  @drm_protected
end

#identifiersArray

Identifiers, array of Identifier instances (EPUB2 reference)



39
40
41
# File 'lib/epubinfo/models/book.rb', line 39

def identifiers
  @identifiers
end

#languagesArray

Languages, array of String instances (EPUB2 reference)



48
49
50
# File 'lib/epubinfo/models/book.rb', line 48

def languages
  @languages
end

#publisherString

Publisher (EPUB2 reference)



25
26
27
# File 'lib/epubinfo/models/book.rb', line 25

def publisher
  @publisher
end

#rightsString

Rights (EPUB2 reference)



53
54
55
# File 'lib/epubinfo/models/book.rb', line 53

def rights
  @rights
end

#sourceString

Source (EPUB2 reference)



44
45
46
# File 'lib/epubinfo/models/book.rb', line 44

def source
  @source
end

#subjectsArray

Subjects, array of String instances (EPUB2 reference)



16
17
18
# File 'lib/epubinfo/models/book.rb', line 16

def subjects
  @subjects
end

#table_of_contentsTableOfContents

Table of Contents



67
68
69
# File 'lib/epubinfo/models/book.rb', line 67

def table_of_contents
  @table_of_contents
end

#titlesArray

Titles, array of String instances (EPUB2 reference)



6
7
8
# File 'lib/epubinfo/models/book.rb', line 6

def titles
  @titles
end

#typeType

Type The type element is used to indicate that the given Publication is of a specialized type



77
78
79
# File 'lib/epubinfo/models/book.rb', line 77

def type
  @type
end

#versionString



71
72
73
# File 'lib/epubinfo/models/book.rb', line 71

def version
  @version
end

Instance Method Details

#to_hashHash

Returns Hash representation of the book



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/epubinfo/models/book.rb', line 112

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,
    :table_of_contents => @table_of_contents,
    :type => @type
  }
end