Sha256: 4537bddeb2d8bc0f80889bf694e12c5681f03ca2a68e16c993c99dbd20de9136
Contents?: true
Size: 782 Bytes
Versions: 65
Compression:
Stored size: 782 Bytes
Contents
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
65 entries across 65 versions & 1 rubygems