aboutsummaryrefslogtreecommitdiffstats
path: root/lib/attachment_to_html/adapters/pdf.rb
diff options
context:
space:
mode:
authorJames McKinney <james@slashpoundbang.com>2015-05-20 16:36:51 +0200
committerJames McKinney <james@slashpoundbang.com>2015-05-20 16:36:51 +0200
commitf2d08c8ece66f8bac867214a65ab1b7f9fe5da92 (patch)
treeb23cca80ebcf4e33bb774468ca4fbf499e43f7e6 /lib/attachment_to_html/adapters/pdf.rb
parentda706b6c05ee7d0be15b59cf0fdec7f6d3ed58ec (diff)
Move common AttachmentToHTML methods to a superclass
Diffstat (limited to 'lib/attachment_to_html/adapters/pdf.rb')
-rw-r--r--lib/attachment_to_html/adapters/pdf.rb50
1 files changed, 3 insertions, 47 deletions
diff --git a/lib/attachment_to_html/adapters/pdf.rb b/lib/attachment_to_html/adapters/pdf.rb
index f99bdc78b..afc8fbcb0 100644
--- a/lib/attachment_to_html/adapters/pdf.rb
+++ b/lib/attachment_to_html/adapters/pdf.rb
@@ -2,10 +2,10 @@
module AttachmentToHTML
module Adapters
# Convert application/pdf documents in to HTML
- class PDF
+ class PDF < Adapter
TOO_MANY_IMAGES = 51
- attr_reader :attachment, :tmpdir
+ attr_reader :tmpdir
# Public: Initialize a PDF converter
#
@@ -14,24 +14,10 @@ module AttachmentToHTML
# :tmpdir - String name of directory to store the
# converted document
def initialize(attachment, opts = {})
- @attachment = attachment
+ super
@tmpdir = opts.fetch(:tmpdir, ::Rails.root.join('tmp'))
end
- # Public: The title to use in the <title> tag
- #
- # Returns a String
- def title
- @title ||= attachment.display_filename
- end
-
- # Public: The contents of the extracted html <body> tag
- #
- # Returns a String
- def body
- @body ||= parse_body
- end
-
# Public: Was the document conversion successful?
#
# Returns a Boolean
@@ -48,14 +34,6 @@ module AttachmentToHTML
match ? match[1] : ''
end
- def has_content?
- !body.gsub(/\s+/,"").gsub(/\<[^\>]*\>/, "").empty?
- end
-
- def contains_images?
- body.match(/<img[^>]*>/mi) ? true : false
- end
-
# Works around https://bugs.freedesktop.org/show_bug.cgi?id=77932 in pdftohtml
def contains_too_many_images?
number_of_images_in_body >= TOO_MANY_IMAGES
@@ -82,28 +60,6 @@ module AttachmentToHTML
html
end
end
-
- def create_tempfile(text)
- tempfile = if RUBY_VERSION.to_f >= 1.9
- Tempfile.new('foiextract', '.',
- :encoding => text.encoding)
- else
- Tempfile.new('foiextract', '.')
- end
- tempfile.print(text)
- tempfile.flush
- tempfile
- end
-
- def cleanup_tempfile(tempfile)
- tempfile.close
- tempfile.delete
- end
-
- def attachment_body
- @attachment_body ||= attachment.body
- end
-
end
end
end