Sha256: 4b3a36f301ba24082e95b4998e5dd9e3a679c6985973c34ecb0513dc6319b7f3
Contents?: true
Size: 1.11 KB
Versions: 1
Compression:
Stored size: 1.11 KB
Contents
require 'optparse' require 'epub/parser' options = {:format => :line} opt = OptionParser.new do |opt| opt.banner = <<EOB Show metadata of an EPUB file Usage: epubinfo [options] EPUBFILE EOB opt.version = EPUB::Parser::VERSION formats = [:line, :json, :yaml] nl_formats = formats.dup nl_last = nl_formats.pop opt.on '-f', '--format=FORMAT', formats, "format of output(#{nl_formats.join(', ')} or #{nl_last}), defaults to line(for console)" do |format| options[:format] = format end end opt.parse!(ARGV) file = ARGV.shift unless file $stdout.puts "error: you must supply an EPUB file name" $stdout.puts opt.help abort end book = EPUB::Parser.parse file data = {'Title' => [book.title]} data.merge!(book.package.metadata.to_hash) data['Unique identifier'] = [book.package.metadata.unique_identifier] data['EPUB Version'] = [book.package.version] if options[:format] == :line key_width = data.keys.map {|k| k.length}.max + 3 data.each_pair do |k, v| puts (k.to_s.capitalize + ':').ljust(key_width) + v.join(', ') end else require options[:format].to_s puts data.__send__("to_#{options[:format]}") end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
epub-parser-0.1.1 | bin/epubinfo |