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



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

#contributorsArray

Contributors, array of Person instances (EPUB2 reference)

Returns:

  • (Array)


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

def contributors
  @contributors
end

#coverCover

Cover

Returns:



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

def cover
  @cover
end

#creatorsArray

Creators, array of Person instances (EPUB2 reference)

Returns:

  • (Array)


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

def creators
  @creators
end

#datesArray

Dates, array of Date instances (EPUB2 reference)

Returns:

  • (Array)


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

def dates
  @dates
end

#descriptionString

Description (EPUB2 reference)

Returns:

  • (String)


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

def description
  @description
end

#drm_protectedBoolean Also known as: drm_protected?

DRM protected

Returns:

  • (Boolean)


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)

Returns:

  • (Array)


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

def identifiers
  @identifiers
end

#languagesArray

Languages, array of String instances (EPUB2 reference)

Returns:

  • (Array)


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

def languages
  @languages
end

#publisherString

Publisher (EPUB2 reference)

Returns:

  • (String)


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

def publisher
  @publisher
end

#rightsString

Rights (EPUB2 reference)

Returns:

  • (String)


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

def rights
  @rights
end

#sourceString

Source (EPUB2 reference)

Returns:

  • (String)


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

def source
  @source
end

#subjectsArray

Subjects, array of String instances (EPUB2 reference)

Returns:

  • (Array)


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

def subjects
  @subjects
end

#titlesArray

Titles, array of String instances (EPUB2 reference)

Returns:

  • (Array)


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

def titles
  @titles
end

#versionString

Returns:

  • (String)


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

def version
  @version
end

Instance Method Details

#to_hashHash

Returns Hash representation of the book

Returns:

  • (Hash)


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