Class: EeePub::OCF

Inherits:
Object
  • Object
show all
Defined in:
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



68
69
70
71
72
# File 'lib/eeepub/ocf.rb', line 68

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

Instance Attribute Details

#containerObject

Returns the value of attribute container.



59
60
61
# File 'lib/eeepub/ocf.rb', line 59

def container
  @container
end

#dirObject

Returns the value of attribute dir.



59
60
61
# File 'lib/eeepub/ocf.rb', line 59

def dir
  @dir
end

Instance Method Details

#save(output_path) ⇒ Object

Save as OCF

Parameters:

  • output_path (String)

    the output file path of ePub



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/eeepub/ocf.rb', line 89

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

  FileUtils.chdir(dir) do
    File.open('mimetype', 'w') do |f|
      f << 'application/epub+zip'
    end

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

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

    %x(zip -X9 \"#{output_path}\" mimetype)
    %x(zip -Xr9D \"#{output_path}\" * -xi mimetype)
  end
end