class ReVIEW::EPUBMaker::Content

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

Attributes

chaptype[RW]

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

file[RW]

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

id[RW]

ID

level[RW]

Header level (from 1)

media[RW]

MIME type

notoc[RW]

Show in TOC? nil:No.

properties[RW]

Properties (EPUB3)

title[RW]

Title

Public Class Methods

initialize(params) click to toggle source
Construct Content object by passing named parameters.
+params+[:file] is required. Others are optional.
# 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

Public Instance Methods

==(other) click to toggle source
# 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) click to toggle source
# File lib/review/epubmaker/content.rb, line 60
def coverimage?(imagefile)
  self.media.start_with?('image') && self.file =~ /#{imagefile}\Z/
end
inspect() click to toggle source
# 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_attribute() click to toggle source
# 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

Private Instance Methods

complement() click to toggle source

Complement other parameters by using file parameter.

# File lib/review/epubmaker/content.rb, line 75
def complement
  if @id.nil?
    @id = @file.gsub(%r{[\\/. ]}, '-')
  end
  if @id =~ /\A[^a-z]/i
    @id = "rv-#{@id}"
  end
  @id = CGI.escape(@id).gsub('%', '_25_')

  if !@file.nil? && @media.nil?
    @media = @file.sub(/.+\./, '').downcase
  end

  case @media
  when 'xhtml', 'xml', 'html'
    @media = 'application/xhtml+xml'
  when 'css'
    @media = 'text/css'
  when 'jpg', 'jpeg', 'image/jpg'
    @media = 'image/jpeg'
  when 'png'
    @media = 'image/png'
  when 'gif'
    @media = 'image/gif'
  when 'svg', 'image/svg'
    @media = 'image/svg+xml'
  when 'ttf', 'otf'
    @media = 'application/vnd.ms-opentype'
  when 'woff'
    @media = 'application/font-woff'
  end

  if @id.nil? || @file.nil? || @media.nil?
    raise "Type error: #{id}, #{file}, #{media}, #{title}, #{notoc}"
  end
end