Sha256: 400ddde13de76dcb74669c1246fe165a975136671648b165785bb60857a4a281

Contents?: true

Size: 823 Bytes

Versions: 5

Compression:

Stored size: 823 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: size ? Onebox::Helpers.pretty_filesize(size.to_i) : nil,
          name: File.basename(uri.path)
        }
      rescue
        nil
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
onebox-1.8.22 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.21 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.20 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.19 lib/onebox/engine/pdf_onebox.rb
onebox-1.8.18 lib/onebox/engine/pdf_onebox.rb