Class: ReVIEW::EPUBMaker::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/review/epubmaker/content.rb

Overview

EPUBMaker::Content represents a content data for EPUBMaker. EPUBMaker#contents takes an array of Content.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file:, id: nil, media: nil, title: nil, level: nil, notoc: nil, properties: nil, chaptype: nil) ⇒ Content

:call-seq:

initialize(params)

Construct Content object by passing named parameters. params[:file] is required. Others are optional.



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/review/epubmaker/content.rb', line 41

def initialize(file:, id: nil, media: nil, title: nil, level: nil, notoc: nil, properties: nil, chaptype: nil)
  @id = id
  @file = file
  @media = media
  @title = title
  @level = level
  @notoc = notoc
  @properties = properties || []
  @chaptype = chaptype
  complement
end

Instance Attribute Details

#chaptypeObject

Chapter type (pre/post/part/nil(body))



31
32
33
# File 'lib/review/epubmaker/content.rb', line 31

def chaptype
  @chaptype
end

#fileObject

File path (will accept #<anchor> suffix also)



19
20
21
# File 'lib/review/epubmaker/content.rb', line 19

def file
  @file
end

#idObject

ID



17
18
19
# File 'lib/review/epubmaker/content.rb', line 17

def id
  @id
end

#levelObject

Header level (from 1)



25
26
27
# File 'lib/review/epubmaker/content.rb', line 25

def level
  @level
end

#mediaObject

MIME type



21
22
23
# File 'lib/review/epubmaker/content.rb', line 21

def media
  @media
end

#notocObject

Show in TOC? nil:No.



27
28
29
# File 'lib/review/epubmaker/content.rb', line 27

def notoc
  @notoc
end

#propertiesObject

Properties (EPUB3)



29
30
31
# File 'lib/review/epubmaker/content.rb', line 29

def properties
  @properties
end

#titleObject

Title



23
24
25
# File 'lib/review/epubmaker/content.rb', line 23

def title
  @title
end

Instance Method Details

#==(other) ⇒ Object



53
54
55
56
57
58
# File 'lib/review/epubmaker/content.rb', line 53

def ==(other)
  return false unless self.class == other.class

  [self.id, self.file, self.media, self.title, self.level, self.notoc, self.chaptype, self.properties] ==
    [other.id, other.file, other.media, other.title, other.level, other.notoc, other.chaptype, other.properties]
end

#coverimage?(imagefile) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/review/epubmaker/content.rb', line 60

def coverimage?(imagefile)
  self.media.start_with?('image') && self.file =~ /#{imagefile}\Z/
end

#inspectObject



33
34
35
# File 'lib/review/epubmaker/content.rb', line 33

def inspect
  "<Content id=#{@id}, file=#{@file}, media=#{@media}, title=#{@title}, level=#{@level}, notoc=#{@notoc}, properties=#{@properties}, chaptype=#{@chaptype}>"
end

#properties_attributeObject



64
65
66
67
68
69
70
# File 'lib/review/epubmaker/content.rb', line 64

def properties_attribute
  if self.properties.size > 0
    %Q( properties="#{self.properties.sort.uniq.join(' ')}")
  else
    ''
  end
end