Sha256: 89d6753e9348f63807d924ea12bc0b54d647df3064cf3219de9a09a0e80dbece

Contents?: true

Size: 806 Bytes

Versions: 38

Compression:

Stored size: 806 Bytes

Contents

# frozen_string_literal: true

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

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
onebox-2.1.2 lib/onebox/engine/pdf_onebox.rb
onebox-2.1.1 lib/onebox/engine/pdf_onebox.rb
onebox-2.1.0 lib/onebox/engine/pdf_onebox.rb
onebox-2.0.2 lib/onebox/engine/pdf_onebox.rb
onebox-2.0.1 lib/onebox/engine/pdf_onebox.rb
onebox-2.0.0 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.30 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.29 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.28.4 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.28.3 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.28.2 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.28.1 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.28 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.27.2 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.27.1 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.26 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.25 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.24 lib/onebox/engine/pdf_onebox.rb