Class: Prophecy::ManifestItem

Inherits:
Object
  • Object
show all
Defined in:
lib/prophecy/manifest.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(book, dir, itempath) ⇒ ManifestItem

Returns a new instance of ManifestItem.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/prophecy/manifest.rb', line 28

def initialize(book, dir, itempath)
  @book = book
  @dir = Pathname.new(File.expand_path(dir))
  @path = Pathname.new(File.expand_path(itempath))

  @href = @path.relative_path_from(@dir)

  if File.basename(@path.to_s) == 'toc.ncx'
    @id = 'ncx'
  elsif !book.cover_image.nil? && File.basename(book.cover_image) == File.basename(itempath)
    @id = 'cover-image'
  else
    @id = self.chapter_id || @href.to_s.downcase.gsub(/[^a-z0-9-]/, '-').gsub(/--+/, '-')
  end
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



26
27
28
# File 'lib/prophecy/manifest.rb', line 26

def dir
  @dir
end

#hrefObject (readonly)

Returns the value of attribute href.



26
27
28
# File 'lib/prophecy/manifest.rb', line 26

def href
  @href
end

#idObject (readonly)

Returns the value of attribute id.



26
27
28
# File 'lib/prophecy/manifest.rb', line 26

def id
  @id
end

#pathObject (readonly)

Returns the value of attribute path.



26
27
28
# File 'lib/prophecy/manifest.rb', line 26

def path
  @path
end

Instance Method Details

#chapter_idObject



44
45
46
47
# File 'lib/prophecy/manifest.rb', line 44

def chapter_id
  ret = @book.chapters.select{|ch| ch.render_path == @path.to_s }.first
  ret.id if ret
end

#media_typeObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/prophecy/manifest.rb', line 49

def media_type
  ret = ""
  # first, use the known list
  ext = File.extname(@path)
  types = {
    '.ncx' => 'application/x-dtbncx+xml',
    '.ttf' => 'application/x-font-ttf',
    '.otf' => 'application/vnd.ms-opentype',
  }
  if types.has_key?(ext)
    ret = types[ext]
  end
  # if not, ask from MIME::Types
  ret = MIME::Types.type_for(File.basename(@path)).first.to_s if ret == ""
  if ret == ""
    warn "Can't determine media type for: #{@path}"
    raise "Unknown Media Type"
  end

  ret
end

#to_sObject



71
72
73
# File 'lib/prophecy/manifest.rb', line 71

def to_s
  @path.to_s
end