From d1782cec6260d6ccb900b04140758106168b8499 Mon Sep 17 00:00:00 2001 From: jugyo Date: Sat, 8 May 2010 01:12:56 +0900 Subject: [PATCH] added doc --- lib/eeepub/ocf.rb | 48 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/lib/eeepub/ocf.rb b/lib/eeepub/ocf.rb index c2c3568..27365c2 100644 --- a/lib/eeepub/ocf.rb +++ b/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 @@ -29,12 +58,20 @@ def build_xml(builder) attr_accessor :dir, :container + # @param [Hash] 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 @@ -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)