Class: Repub::Epub::Item

Inherits:
Object show all
Includes:
ContainerItem
Defined in:
lib/repub/epub/container_item.rb

Overview

Wrapper class for ePub items that do not have specialized classes e.g. HTML files, CSSs etc.

Instance Attribute Summary

Attributes included from ContainerItem

#file_path, #media_type

Instance Method Summary collapse

Methods included from ContainerItem

#document?

Constructor Details

#initialize(file_path, media_type = nil) ⇒ Item

Returns a new instance of Item.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/repub/epub/container_item.rb', line 23

def initialize(file_path, media_type = nil)
  @file_path = file_path.strip
  @media_type = media_type || case @file_path.downcase
    when /.*\.html?$/
      'application/xhtml+xml'
    when /.*\.css$/
      'text/css'
    when /.*\.(jpeg|jpg)$/
      'image/jpeg'
    when /.*\.png$/
      'image/png'
    when /.*\.gif$/
      'image/gif'
    when /.*\.svg$/
      'image/svg+xml'
    when /.*\.ncx$/
      'application/x-dtbncx+xml'
    when /.*\.opf$/
      'application/oebps-package+xml'
    else
      raise 'Unknown media type'
  end
end