Sha256: 0e4bb022702e20bf8e0c2a8955c230f8540d7e0d5e0e6b78443109d9ca2c17fc
Contents?: true
Size: 780 Bytes
Versions: 17
Compression:
Stored size: 780 Bytes
Contents
module Onebox module Engine class PdfOnebox include Engine include LayoutSupport matches_regexp(/^(https?:)?\/\/.*\.pdf(\?.*)?$/i) always_https private def data html_entities = HTMLEntities.new 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: Onebox::Helpers.pretty_filesize(size.to_i), name: File.basename(uri.path)} rescue nil end end end end
Version data entries
17 entries across 17 versions & 1 rubygems