Class: Thepub::Epub::OPF
- Inherits:
-
Object
- Object
- Thepub::Epub::OPF
- Includes:
- ContainerItem
- Defined in:
- lib/thepub/epub/opf.rb
Overview
Open Packaging Format (OPF) 2.0 wrapper (see www.idpf.org/2007/opf/OPF_2.0_final_spec.html)
Defined Under Namespace
Classes: Metadata
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Attributes included from ContainerItem
Instance Method Summary collapse
- #<<(item) ⇒ Object
-
#initialize(uid, file_path = 'package.opf') ⇒ OPF
constructor
A new instance of OPF.
- #save ⇒ Object
- #to_xml ⇒ Object
Methods included from ContainerItem
Constructor Details
#initialize(uid, file_path = 'package.opf') ⇒ OPF
Returns a new instance of OPF.
13 14 15 16 17 18 19 |
# File 'lib/thepub/epub/opf.rb', line 13 def initialize(uid, file_path = 'package.opf') @file_path = file_path @media_type = 'application/oebps-package+xml' @metadata = Metadata.new('Untitled', 'en', uid, Date.today.to_s) @items = [] @ncx = nil end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
76 77 78 |
# File 'lib/thepub/epub/opf.rb', line 76 def items @items end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
75 76 77 |
# File 'lib/thepub/epub/opf.rb', line 75 def @metadata end |
Instance Method Details
#<<(item) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/thepub/epub/opf.rb', line 78 def <<(item) if item.kind_of? NCX @ncx = item elsif item.kind_of? ContainerItem @items << item elsif item.is_a? String @items << Item.new(item) else raise "Unsupported item class: #{item.class}" end end |
#save ⇒ Object
104 105 106 107 108 |
# File 'lib/thepub/epub/opf.rb', line 104 def save File.open(@file_path, 'w') do |f| f << to_xml end end |
#to_xml ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/thepub/epub/opf.rb', line 90 def to_xml out = '' builder = Builder::XmlMarkup.new(:target => out) builder.instruct! builder.package :xmlns => "http://www.idpf.org/2007/opf", 'unique-identifier' => "dcidid", 'version' => "2.0" do @metadata.to_xml(builder) manifest_to_xml(builder) spine_to_xml(builder) end out end |