lib/epub/publication/package/manifest.rb in epub-parser-0.1.0 vs lib/epub/publication/package/manifest.rb in epub-parser-0.1.1
- old
+ new
@@ -26,50 +26,63 @@
def cover_image
items.selector {|i| i.properties.include? 'cover-image'}.first
end
def items
- @items.collect {|id, item| item}
+ @items.values
end
def [](item_id)
@items[item_id]
end
class Item
+ # @!attribute [rw] manifest
+ # @return [Manifest] Returns the value of manifest
+ # @!attribute [rw] id
+ # @return [String] Returns the value of id
+ # @!attribute [rw] href
+ # @return [Addressable::URI] Returns the value of href
+ # @!attribute [rw] media_type
+ # @return [String] Returns the value of media_type
+ # @!attribute [rw] properties
+ # @return [Array<String>] Returns the value of properties
+ # @!attribute [rw] media_overlay
+ # @return [String] Returns the value of media_overlay
+ # @!attribute [rw] fallback
+ # @return [Item] Returns the value of attribute fallback
attr_accessor :manifest,
- :id, :href, :media_type, :fallback, :properties, :media_overlay,
- :iri
+ :id, :href, :media_type, :fallback, :properties, :media_overlay
- # To do: Handle circular fallback chain
+ # @todo Handle circular fallback chain
def fallback_chain
- return @fallback_chain if @fallback_chain
- @fallback_chain = traverse_fallback_chain([])
+ @fallback_chain ||= traverse_fallback_chain([])
end
def read
+ rootfile = Addressable::URI.parse(manifest.package.book.ocf.container.rootfile.full_path)
Zip::Archive.open(manifest.package.book.epub_file) {|zip|
- zip.fopen(iri.to_s).read
+ path = rootfile + href.request_uri
+ zip.fopen(path.to_s).read
}
end
- # To do: Handle circular fallback chain
+ # @todo Handle circular fallback chain
def use_fallback_chain(options = {})
supported = EPUB::MediaType::CORE
if ad = options[:supported]
supported = supported | (ad.respond_to?(:to_ary) ? ad : [ad])
end
if del = options[:unsupported]
supported = supported - (del.respond_to?(:to_ary) ? del : [del])
end
- if supported.include? media_type
- yield self
- elsif fallback
- fallback.use_fallback_chain(options) {|fb| yield fb}
- else
- raise EPUB::MediaType::UnsupportedError
+ return yield self if supported.include? media_type
+ if (bindings = manifest.package.bindings) && (binding_media_type = bindings[media_type])
+ return yield binding_media_type.handler
end
+ return fallback.use_fallback_chain(options) {|fb| yield fb} if fallback
+ raise EPUB::MediaType::UnsupportedError
end
protected
def traverse_fallback_chain(chain)