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.48 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.47 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.46 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.45 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.44 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.43 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.42 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.41 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.40 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.39 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.38 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.36 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.35 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.34 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.33 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.32 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.31 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.30 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.29 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.28 lib/onebox/engine/pdf_onebox.rb