lib/ebook_renamer/helpers.rb in ebook_renamer-0.0.2 vs lib/ebook_renamer/helpers.rb in ebook_renamer-0.0.3

- old
+ new

@@ -2,19 +2,26 @@ require 'fileutils' require 'shellwords' module EbookRenamer class Helpers + + EbookMetaNotInstall = Class.new(StandardError) + class << self # Extract meta data from the input file using the ebook-meta tool # # @param [String] filename the input file name # @param [String] binary the executable for use to extract the metadata # @return [String] result of the output from running the command def meta(filename, binary = 'ebook-meta') + binary_path = which(binary) + + raise EbookMetaNotInstall, "Need to install ebook-meta to use this gem" if binary_path.nil? + command = [ - binary, + binary_path, Shellwords.escape(filename) ] stdout_str, stderr_str, status = Open3.capture3(command.join(" ")) raise "Problem processing #{filename}" unless status.success?