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.
69 70 71 72 73 |
# File 'lib/eeepub/ocf.rb', line 69 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.
60 61 62 |
# File 'lib/eeepub/ocf.rb', line 60 def container @container end |
#dir ⇒ Object
Returns the value of attribute dir.
60 61 62 |
# File 'lib/eeepub/ocf.rb', line 60 def dir @dir end |
Instance Method Details
#render ⇒ String
Stream OCF
109 110 111 112 113 114 115 |
# File 'lib/eeepub/ocf.rb', line 109 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
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/eeepub/ocf.rb', line 90 def save(output_path) output_path = File.(output_path) create_epub do mimetype = Zip::OutputStream::open(output_path) do |os| os.put_next_entry("mimetype") os << "application/epub+zip" end zipfile = Zip::File.open(output_path) Dir.glob('**/*').each do |path| zipfile.add(path, path) end zipfile.commit end FileUtils.remove_entry_secure dir end |