class GEPUB::Manifest
Attributes
opf_version[RW]
Public Class Methods
new(opf_version = '3.0', id_pool = Package::IDPool.new) { |self| ... }
click to toggle source
# File lib/gepub/manifest.rb, line 34 def initialize(opf_version = '3.0', id_pool = Package::IDPool.new) @id_pool = id_pool @attributes = {} @items = {} @items_by_href = {} @opf_version = opf_version yield self if block_given? end
parse(manifest_xml, opf_version = '3.0', id_pool = Package::IDPool.new)
click to toggle source
# File lib/gepub/manifest.rb, line 7 def self.parse(manifest_xml, opf_version = '3.0', id_pool = Package::IDPool.new) Manifest.new(opf_version, id_pool) { |manifest| manifest.instance_eval { @xml = manifest_xml @namespaces = @xml.namespaces @attributes = attr_to_hash(@xml.attributes) @items = {} @items_by_href = {} @xml.xpath("//#{ns_prefix(OPF_NS)}:manifest/#{ns_prefix(OPF_NS)}:item", @namespaces).map { |item| i = Item.create(self, attr_to_hash(item.attributes)) @items[i.id] = i @items_by_href[i.href] = i } } } end
Public Instance Methods
add_item(id,href,media_type, attributes = {})
click to toggle source
# File lib/gepub/manifest.rb, line 55 def add_item(id,href,media_type, attributes = {}) id ||= @id_pool.generate_key(:prefix=>'item_'+ File.basename(href,'.*'), :without_count => true) @items[id] = item = Item.new(id,href,media_type,self, attributes) @items_by_href[href] = item item end
id()
click to toggle source
# File lib/gepub/manifest.rb, line 30 def id @attributes['id'] end
id=(val)
click to toggle source
# File lib/gepub/manifest.rb, line 26 def id=(val) @attributes['id'] = val end
item_by_href(href)
click to toggle source
# File lib/gepub/manifest.rb, line 51 def item_by_href(href) @items_by_href[href] end
item_list()
click to toggle source
# File lib/gepub/manifest.rb, line 43 def item_list @items.dup end
items()
click to toggle source
# File lib/gepub/manifest.rb, line 47 def items @items.dup end
register_item(item)
click to toggle source
# File lib/gepub/manifest.rb, line 71 def register_item(item) raise "id '#{item.id}' is already in use." if @id_pool[item.id] @id_pool[item.id] = true end
to_xml(builder)
click to toggle source
# File lib/gepub/manifest.rb, line 62 def to_xml(builder) builder.manifest(@attributes) { @items.each { |_itemid, item| item.to_xml(builder, @opf_version) } } end
unregister_item(item)
click to toggle source
# File lib/gepub/manifest.rb, line 76 def unregister_item(item) @items.delete(item.id) @items_by_href.delete(item.href) @id_pool[item.id] = nil end