Sha256: 6086400e6e8092f9c3dcba3ad5630e1c3f5b8449cb9c50d54aa3f00c0ecf99d9

Contents?: true

Size: 688 Bytes

Versions: 6

Compression:

Stored size: 688 Bytes

Contents

require 'pry'
module EbooksRenamer
  class PdfParser
    class << self
      def parse(filename)
        File.open(filename, 'rb') do |io|
          reader = PDF::Reader.new(io)
          if reader && reader.info && reader.info[:Title].present?
            OpenStruct.new title:  reader.info[:Title],
                           author: reader.info[:Author],
                           pages:  reader.page_count
          end
        end
      rescue Exception => e
        # Note: we skip the file that we can't process
        # and allow the process to continue
        puts "Skip file '#{filename}'"
        puts "Due to the unexpected error: #{e.message}"
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ebooks_renamer-0.1.3 lib/ebooks_renamer/pdf_parser.rb
ebooks_renamer-0.1.2 lib/ebooks_renamer/pdf_parser.rb
ebooks_renamer-0.1.1 lib/ebooks_renamer/pdf_parser.rb
ebooks_renamer-0.1.0 lib/ebooks_renamer/pdf_parser.rb
ebooks_renamer-0.0.4 lib/ebooks_renamer/pdf_parser.rb
ebooks_renamer-0.0.3 lib/ebooks_renamer/pdf_parser.rb