Sha256: 0e4bb022702e20bf8e0c2a8955c230f8540d7e0d5e0e6b78443109d9ca2c17fc

Contents?: true

Size: 780 Bytes

Versions: 17

Compression:

Stored size: 780 Bytes

Contents

module Onebox
  module Engine
    class PdfOnebox
      include Engine
      include LayoutSupport

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

      private

      def data
        html_entities = HTMLEntities.new
        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: Onebox::Helpers.pretty_filesize(size.to_i), name: File.basename(uri.path)}
      rescue
        nil
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
onebox-1.8.17 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.16 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.15 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.14 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.13 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.12 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.11 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.10 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.9 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.8 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.7 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.6 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.5 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.4 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.3 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.2 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.1 lib/onebox/engine/pdf_onebox.rb