Class: EpubTools::UnpackEbook
- Inherits:
-
Object
- Object
- EpubTools::UnpackEbook
- Includes:
- Loggable
- Defined in:
- lib/epub_tools/unpack_ebook.rb
Overview
Unpacks an EPUB (.epub file) into a directory
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ UnpackEbook
constructor
Initializes the class.
-
#run ⇒ Object
Extracts all entries from the EPUB into the output directory.
Methods included from Loggable
Constructor Details
#initialize(options = {}) ⇒ UnpackEbook
Initializes the class
14 15 16 17 18 19 |
# File 'lib/epub_tools/unpack_ebook.rb', line 14 def initialize( = {}) @epub_file = File.(.fetch(:epub_file)) output_dir = [:output_dir] @output_dir = output_dir.nil? || output_dir.empty? ? default_dir : output_dir @verbose = [:verbose] || false end |
Instance Method Details
#run ⇒ Object
Extracts all entries from the EPUB into the output directory. Returns the output directory.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/epub_tools/unpack_ebook.rb', line 23 def run validate! FileUtils.mkdir_p(@output_dir) Zip::File.open(@epub_file) do |zip| zip.each do |entry| dest_path = File.join(@output_dir, entry.name) if entry.directory? FileUtils.mkdir_p(dest_path) else FileUtils.mkdir_p(File.dirname(dest_path)) entry.extract(dest_path) { true } end end end log "Unpacked #{File.basename(@epub_file)} to #{@output_dir}" @output_dir end |