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