Class: EPInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/epinfo.rb,
lib/epinfo/version.rb

Constant Summary collapse

VERSION =
"1.0.4"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.output(*args) ⇒ Object



6
7
8
9
# File 'lib/epinfo.rb', line 6

def self.output(*args)
  output = EPInfo.new
  output.output(*args)
end

Instance Method Details

#book_desc(book) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/epinfo.rb', line 41

def book_desc(book)
  cover = book.cover
  if cover
    cover = "#{cover.original_file_name}"
  end

  return <<-EOB
titles: #{book.titles.join()}
creators: #{book.creators.map{|c| "#{c.name}(#{c.role||'-'})"}.join(', ')}
subjects: #{book.subjects.join(", ")}
description: #{book.description}
publisher: #{book.publisher}
contributors: #{book.contributors.map{|c| "#{c.name}(#{c.role||'-'})"}.join(', ')}
dates: #{book.dates.map{|d| "#{d.date_str}(#{d.event||'-'})"}.join(', ')}
identifiers: #{book.identifiers.map(&:identifier).join(', ')}
epub_version: #{book.version}
source: #{book.source}
languages: #{book.languages.join(', ')}
rights: #{book.rights}
drm_protected: #{book.drm_protected}
cover: #{cover}
  EOB
end

#output(*args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/epinfo.rb', line 11

def output(*args)

  opts = OptionParser.new do |opts|
    opts.banner = "Usage: epinfo [filename]\n"

    opts.on('-h', '--help', 'show this screen') do
      puts opts
      exit
    end
    opts.on('-v', '--version', 'show version information') do
      puts EPInfo::VERSION
      exit
    end
  end

  begin
    opts.parse!(args)
    if args.size != 1
      #invalid option
      puts opts
      exit
    end
    book = EPUBInfo.get(args[0])
    puts book_desc(book)

  rescue => e
    warn e
  end
end