Sha256: 2c76427a14a7a8a40d901df4cb13a8c02c907e69c4f8f45fa0e0791d420348ff

Contents?: true

Size: 664 Bytes

Versions: 6

Compression:

Stored size: 664 Bytes

Contents

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 => 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.2.6 lib/ebooks_renamer/pdf_parser.rb
ebooks_renamer-0.2.5 lib/ebooks_renamer/pdf_parser.rb
ebooks_renamer-0.2.4 lib/ebooks_renamer/pdf_parser.rb
ebooks_renamer-0.2.3 lib/ebooks_renamer/pdf_parser.rb
ebooks_renamer-0.2.2 lib/ebooks_renamer/pdf_parser.rb
ebooks_renamer-0.1.5 lib/ebooks_renamer/pdf_parser.rb