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.2.14 lib/onebox/engine/pdf_onebox.rb
onebox-2.2.13 lib/onebox/engine/pdf_onebox.rb
onebox-2.2.12 lib/onebox/engine/pdf_onebox.rb
onebox-2.2.11 lib/onebox/engine/pdf_onebox.rb
onebox-2.2.10 lib/onebox/engine/pdf_onebox.rb
onebox-2.2.9 lib/onebox/engine/pdf_onebox.rb
onebox-2.2.8 lib/onebox/engine/pdf_onebox.rb
onebox-2.2.6 lib/onebox/engine/pdf_onebox.rb
onebox-2.2.5 lib/onebox/engine/pdf_onebox.rb
onebox-2.2.4 lib/onebox/engine/pdf_onebox.rb
onebox-2.2.2 lib/onebox/engine/pdf_onebox.rb
onebox-2.2.1 lib/onebox/engine/pdf_onebox.rb
onebox-2.2.0 lib/onebox/engine/pdf_onebox.rb
onebox-2.1.9 lib/onebox/engine/pdf_onebox.rb
onebox-2.1.8 lib/onebox/engine/pdf_onebox.rb
onebox-2.1.7 lib/onebox/engine/pdf_onebox.rb
onebox-2.1.6 lib/onebox/engine/pdf_onebox.rb
onebox-2.1.5 lib/onebox/engine/pdf_onebox.rb
onebox-2.1.4 lib/onebox/engine/pdf_onebox.rb
onebox-2.1.3 lib/onebox/engine/pdf_onebox.rb