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.89 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.88 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.87 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.86 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.85 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.84 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.83 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.82 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.81 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.80 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.79 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.78 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.77 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.76 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.75 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.74 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.73 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.72 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.71 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.70 lib/onebox/engine/pdf_onebox.rb