Sha256: f6edc3e150ff30f2d3ef7618c7dc55ae11357a9bd1905a56d0018c3a272d48bc
Contents?: true
Size: 1.11 KB
Versions: 1
Compression:
Stored size: 1.11 KB
Contents
require 'tmpdir' require 'optparse' require 'epub/parser' Version = EPUB::Parser::VERSION options = {:format => :line} opt = OptionParser.new do |opt| opt.banner = <<EOB Show metadata of an EPUB file Usage: epubinfo [options] EPUBFILE EOB opt.on '-f', '--format=FORMAT', [:line, :json, :yaml], 'format of output(line, json or yaml), 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 exit! end Dir.mktmpdir('epub-parser') do |dir| book = EPUB::Parser.parse file, dir 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 end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
epub-parser-0.0.8 | bin/epubinfo |