class EPUB::Publication::Package::Manifest::Item

Attributes

fallback[RW]

@!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,
                           which is relative IRI from rootfile(OPF file)

@!attribute [rw] media_type

@return [String] Returns the value of media_type

@!attribute [rw] properties

@return [Set<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
href[RW]

@!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,
                           which is relative IRI from rootfile(OPF file)

@!attribute [rw] media_type

@return [String] Returns the value of media_type

@!attribute [rw] properties

@return [Set<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
id[RW]

@!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,
                           which is relative IRI from rootfile(OPF file)

@!attribute [rw] media_type

@return [String] Returns the value of media_type

@!attribute [rw] properties

@return [Set<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
manifest[RW]

@!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,
                           which is relative IRI from rootfile(OPF file)

@!attribute [rw] media_type

@return [String] Returns the value of media_type

@!attribute [rw] properties

@return [Set<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
media_overlay[RW]

@!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,
                           which is relative IRI from rootfile(OPF file)

@!attribute [rw] media_type

@return [String] Returns the value of media_type

@!attribute [rw] properties

@return [Set<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
media_type[RW]

@!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,
                           which is relative IRI from rootfile(OPF file)

@!attribute [rw] media_type

@return [String] Returns the value of media_type

@!attribute [rw] properties

@return [Set<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
properties[R]

Public Class Methods

new() click to toggle source
# File lib/epub/publication/package/manifest.rb, line 74
def initialize
  @properties = Set.new
end

Public Instance Methods

content_document() click to toggle source
# File lib/epub/publication/package/manifest.rb, line 129
def content_document
  return nil unless %w[application/xhtml+xml image/svg+xml].include? media_type
  @content_document ||= Parser::ContentDocument.new(self).parse
end
cover_image?() click to toggle source
# File lib/epub/publication/package/manifest.rb, line 107
def cover_image?
  properties.include? 'cover-image'
end
entry_name() click to toggle source

full path in archive

# File lib/epub/publication/package/manifest.rb, line 88
def entry_name
  rootfile = manifest.package.book.ocf.container.rootfile.full_path
  Addressable::URI.unescape(rootfile + href.normalize.request_uri)
end
fallback_chain() click to toggle source

@todo Handle circular fallback chain

# File lib/epub/publication/package/manifest.rb, line 83
def fallback_chain
  @fallback_chain ||= traverse_fallback_chain([])
end
find_item_by_relative_iri(iri) click to toggle source

@param iri [Addressable::URI] relative iri @return [Item] @return [nil] when item not found @raise ArgumentError when iri is not relative @raise ArgumentError when iri starts with “/”(slash) @note Algorithm stolen form Rack::Utils#clean_path_info

# File lib/epub/publication/package/manifest.rb, line 146
def find_item_by_relative_iri(iri)
  raise ArgumentError, "Not relative: #{iri.inspect}" unless iri.relative?
  raise ArgumentError, "Start with slash: #{iri.inspect}" if iri.to_s.start_with? Addressable::URI::SLASH
  target_href = href + iri
  segments = target_href.to_s.split(Addressable::URI::SLASH)
  clean_segments = []
  segments.each do |segment|
    next if segment.empty? || segment == '.'
    segment == '..' ? clean_segments.pop : clean_segments << segment
  end
  target_iri = Addressable::URI.parse(clean_segments.join(Addressable::URI::SLASH))
  manifest.items.find { |item| item.href == target_iri}
end
inspect() click to toggle source
# File lib/epub/publication/package/manifest.rb, line 160
def inspect
  "#<%{class}:%{object_id} %{manifest} %{attributes}>" % {
    :class      => self.class,
    :object_id  => inspect_object_id,
    :manifest   => "@manifest=#{@manifest.inspect_simply}",
    :attributes => inspect_instance_variables(exclude: [:@manifest])
  }
end
itemref() click to toggle source

@return [Package::Spine::Itemref] @return nil when no Itemref refers this Item

# File lib/epub/publication/package/manifest.rb, line 136
def itemref
  manifest.package.spine.itemrefs.find {|itemref| itemref.idref == id}
end
nav?() click to toggle source
properties=(props) click to toggle source
# File lib/epub/publication/package/manifest.rb, line 78
def properties=(props)
  @properties = props.kind_of?(Set) ? props : Set.new(props)
end
read() click to toggle source
# File lib/epub/publication/package/manifest.rb, line 93
def read
  Zip::Archive.open(manifest.package.book.epub_file) {|zip|
    zip.fopen(entry_name).read
  }
end
use_fallback_chain(options = {}) { |self| ... } click to toggle source

@todo Handle circular fallback chain

# File lib/epub/publication/package/manifest.rb, line 112
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

  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::UnsupportedMediaType
end
xhtml?() click to toggle source
# File lib/epub/publication/package/manifest.rb, line 99
def xhtml?
  media_type == 'application/xhtml+xml'
end

Protected Instance Methods

traverse_fallback_chain(chain) click to toggle source
# File lib/epub/publication/package/manifest.rb, line 171
def traverse_fallback_chain(chain)
  chain << self
  return chain unless fallback
  fallback.traverse_fallback_chain(chain)
end