Class: EeePub::OCF
- Inherits:
-
Object
- Object
- EeePub::OCF
- Defined in:
- lib/eeepub/ocf.rb
Overview
Class to create OCF
Defined Under Namespace
Classes: Container
Instance Attribute Summary collapse
-
#container ⇒ Object
Returns the value of attribute container.
-
#dir ⇒ Object
Returns the value of attribute dir.
Instance Method Summary collapse
-
#initialize(values) ⇒ OCF
constructor
A new instance of OCF.
-
#render ⇒ String
Stream OCF.
-
#save(output_path) ⇒ Object
Save as OCF.
Constructor Details
#initialize(values) ⇒ OCF
Returns a new instance of OCF.
70 71 72 73 74 |
# File 'lib/eeepub/ocf.rb', line 70 def initialize(values) values.each do |k, v| self.send(:"#{k}=", v) end end |
Instance Attribute Details
#container ⇒ Object
Returns the value of attribute container.
61 62 63 |
# File 'lib/eeepub/ocf.rb', line 61 def container @container end |
#dir ⇒ Object
Returns the value of attribute dir.
61 62 63 |
# File 'lib/eeepub/ocf.rb', line 61 def dir @dir end |
Instance Method Details
#render ⇒ String
Stream OCF
110 111 112 113 114 115 116 |
# File 'lib/eeepub/ocf.rb', line 110 def render create_epub do temp_file = Tempfile.new("ocf") self.save(temp_file.path) return temp_file.read end end |
#save(output_path) ⇒ Object
Save as OCF
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/eeepub/ocf.rb', line 91 def save(output_path) output_path = File.(output_path) create_epub do mimetype = Zip::ZipOutputStream::open(output_path) do |os| os.put_next_entry("mimetype", nil, nil, Zip::ZipEntry::STORED, Zlib::NO_COMPRESSION) os << "application/epub+zip" end zipfile = Zip::ZipFile.open(output_path) Dir.glob('**/*').each do |path| zipfile.add(path, path) end zipfile.commit end end |