Class: EPUBMaker::Content

Inherits:
Object show all
Defined in:
lib/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(fileorhash, id = nil, media = nil, title = nil, level = nil, notoc = nil, properties = nil, chaptype = nil) ⇒ Content

:call-seq:

initialize(file, id, media, title, level, notoc)
initialize(hash)

Construct Content object by passing a sequence of parameters or hash. Keys of hash relate with each parameters. file (or hash[“file”]) is required. Others are optional.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/epubmaker/content.rb', line 42

def initialize(fileorhash, id = nil, media = nil, title = nil, level = nil, notoc = nil, properties = nil, chaptype = nil)
  if fileorhash.instance_of?(Hash)
    @id = fileorhash['id']
    @file = fileorhash['file']
    @media = fileorhash['media']
    @title = fileorhash['title']
    @level = fileorhash['level']
    @notoc = fileorhash['notoc']
    @properties = fileorhash['properties'] || []
    @chaptype = fileorhash['chaptype']
  else
    @file = fileorhash
    @id = id
    @media = media
    @title = title
    @level = level
    @notoc = notoc
    @properties = properties || []
    @chaptype = chaptype
  end
  complement
end

Instance Attribute Details

#chaptypeObject

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



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

def chaptype
  @chaptype
end

#fileObject

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



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

def file
  @file
end

#idObject

ID



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

def id
  @id
end

#levelObject

Header level (from 1)



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

def level
  @level
end

#mediaObject

MIME type



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

def media
  @media
end

#notocObject

Show in TOC? nil:No.



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

def notoc
  @notoc
end

#propertiesObject

Properties (EPUB3)



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

def properties
  @properties
end

#titleObject

Title



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

def title
  @title
end

Instance Method Details

#==(other) ⇒ Object



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

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

#inspectObject



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

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