Sha256: 3f2611947373e9c8ce0b46067a860d360978038c5b047ed02b7e1dc7871fee98
Contents?: true
Size: 1.1 KB
Versions: 1
Compression:
Stored size: 1.1 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.metadata.to_hash) data['Unique identifier'] = [book.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.2 | bin/epubinfo |