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