Sha256: a29d83fc592251be66c92f9eb1e2148ce44e8d16a1937d391b4a666df8bfea92

Contents?: true

Size: 813 Bytes

Versions: 34

Compression:

Stored size: 813 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)
        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

34 entries across 34 versions & 1 rubygems

Version Path
onebox-1.9.23 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.22 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.21 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.20 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.19 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.18 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.17 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.16 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.15 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.14 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.13 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.12 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.11 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.10 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.9 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.8 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.7 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.6 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.5 lib/onebox/engine/pdf_onebox.rb
onebox-1.9.4 lib/onebox/engine/pdf_onebox.rb