Class: EeePub::OCF

Inherits:
Object
  • Object
show all
Defined in:
lib/eeepub/lib/eeepub/ocf.rb

Overview

Class to create OCF

Defined Under Namespace

Classes: Container

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ OCF

Returns a new instance of OCF.

Examples:

EeePub::OCF.new(
  :dir => '/path/to/dir',
  :container => 'container.opf'
)

Parameters:

  • values (Hash<Symbol, Object>)

    the values of symbols and objects for OCF



71
72
73
74
75
# File 'lib/eeepub/lib/eeepub/ocf.rb', line 71

def initialize(values)
  values.each do |k, v|
    self.send(:"#{k}=", v)
  end
end

Instance Attribute Details

#containerObject

Returns the value of attribute container.



62
63
64
# File 'lib/eeepub/lib/eeepub/ocf.rb', line 62

def container
  @container
end

#dirObject

Returns the value of attribute dir.



62
63
64
# File 'lib/eeepub/lib/eeepub/ocf.rb', line 62

def dir
  @dir
end

Instance Method Details

#save(output_path) ⇒ Object

Save as OCF

Parameters:

  • output_path (String)

    the output file path of ePub



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/eeepub/lib/eeepub/ocf.rb', line 92

def save(output_path)
  output_path = File.expand_path(output_path)

  FileUtils.chdir(dir) do

    meta_inf = 'META-INF'
    FileUtils.mkdir_p(meta_inf)

    container.save(File.join(meta_inf, 'container.xml'))

    Zippy.create output_path do |zip|
      zip['mimetype'] = 'application/epub+zip'
      Dir.glob('**/*').each do |filename|
        zip[filename] = IO.read(filename) unless File.directory?(filename)
      end
    end
 
  end
end