Skip to content

Commit

Permalink
added doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jugyo committed May 7, 2010
1 parent 17608e6 commit d1782ce
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions lib/eeepub/ocf.rb
@@ -1,21 +1,50 @@
module EeePub
# Class to create OCF
class OCF
# Class for 'container.xml' of OCF
class Container < ContainerItem
attr_accessor :rootfiles

def set_values(arg)
# @param [String or Array or Hash]
#
# @example
# # with String
# EeePub::OCF::Container.new('container.opf')
#
# @example
# # with Array
# EeePub::OCF::Container.new(['container.opf', 'other.opf'])
#
# @example
# # with Hash
# EeePub::OCF::Container.new(
# :rootfiles => [
# {:full_path => 'container.opf', :media_type => 'application/oebps-package+xml'}
# ]
# )
def initialize(arg)
case arg
when String
super(
set_values(
:rootfiles => [
{:full_path => arg, :media_type => guess_media_type(arg)}
]
)
else
super
when Array
# TODO: spec
set_values(
:rootfiles => arg.keys.map { |k|
filename = arg[k]
{:full_path => filename, :media_type => guess_media_type(filename)}
}
)
when Hash
set_values(arg)
end
end

private

def build_xml(builder)
builder.container :xmlns => "urn:oasis:names:tc:opendocument:xmlns:container", :version => "1.0" do
builder.rootfiles do
Expand All @@ -29,12 +58,20 @@ def build_xml(builder)

attr_accessor :dir, :container

# @param [Hash<Symbol, Object>] values the values of symbols and objects for OCF
#
# @example
# EeePub::OCF.new(
# :dir => '/path/to/dir',
# :container => 'container.opf'
# )
def initialize(values)
values.each do |k, v|
self.send(:"#{k}=", v)
end
end

# Set container
def container=(arg)
case arg
when String
Expand All @@ -44,6 +81,9 @@ def container=(arg)
end
end

# Save as OCF
#
# @param [String] output_path the output file path of ePub
def save(output_path)
output_path = File.expand_path(output_path)

Expand Down

0 comments on commit d1782ce

Please sign in to comment.