Class: Prophecy::ManifestItem
- Inherits:
-
Object
- Object
- Prophecy::ManifestItem
- Defined in:
- lib/prophecy/manifest.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #chapter_id ⇒ Object
-
#initialize(book, dir, itempath) ⇒ ManifestItem
constructor
A new instance of ManifestItem.
- #media_type ⇒ Object
- #to_s ⇒ Object
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.(dir)) @path = Pathname.new(File.(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
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
26 27 28 |
# File 'lib/prophecy/manifest.rb', line 26 def dir @dir end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
26 27 28 |
# File 'lib/prophecy/manifest.rb', line 26 def href @href end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
26 27 28 |
# File 'lib/prophecy/manifest.rb', line 26 def id @id end |
#path ⇒ Object (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_id ⇒ Object
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_type ⇒ Object
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_s ⇒ Object
71 72 73 |
# File 'lib/prophecy/manifest.rb', line 71 def to_s @path.to_s end |