require 'open3' module Bookshelf module Parser autoload :HTML , "bookshelf/parser/html" autoload :PDF , "bookshelf/parser/pdf" autoload :Epub , "bookshelf/parser/epub" autoload :Mobi , "bookshelf/parser/mobi" autoload :Txt , "bookshelf/parser/txt" class Base # The e-book directory. # attr_accessor :book_dir def self.parse(book_dir) new(book_dir).parse end def initialize(book_dir) @book_dir = Pathname.new(book_dir) end # Return directory's basename. # def name File.basename(book_dir) end # Return the configuration file. # def config Bookshelf.config(book_dir) end # Render a eRb template using +locals+ as data seed. # def render_template(file, locals = {}) ERB.new(File.read(file)).result OpenStruct.new(locals).instance_eval{ binding } end def spawn_command(cmd) begin stdout_and_stderr, status = Open3.capture2e(*cmd) rescue Errno::ENOENT => e puts e.message else puts stdout_and_stderr unless status.success? status.success? end end end end end