Sha256: 4537bddeb2d8bc0f80889bf694e12c5681f03ca2a68e16c993c99dbd20de9136

Contents?: true

Size: 782 Bytes

Versions: 65

Compression:

Stored size: 782 Bytes

Contents

module Onebox
  module Engine
    class PdfOnebox
      include Engine
      include LayoutSupport

      matches_regexp(/^(https?:)?\/\/.*\.pdf(\?.*)?$/i)
      always_https

      private

      def data
        pdf_info = get_pdf_info
        raise "Unable to read pdf file: #{@url}" if pdf_info.nil?

        result = { link: link,
                   title: pdf_info[:name],
                   filesize: pdf_info[:filesize]
                  }
        result
      end

      def get_pdf_info
        uri = URI.parse(@url)
        size = Onebox::Helpers.fetch_content_length(@url)
        return {
          filesize: size ? Onebox::Helpers.pretty_filesize(size.to_i) : nil,
          name: File.basename(uri.path)
        }
      rescue
        nil
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
onebox-1.8.69 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.68 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.67 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.66 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.65 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.64 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.63 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.62 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.61 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.60 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.59 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.58 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.57 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.55 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.54 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.53 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.52 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.51 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.50 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.49 lib/onebox/engine/pdf_onebox.rb