diff options
author | James McKinney <james@slashpoundbang.com> | 2015-05-20 16:36:51 +0200 |
---|---|---|
committer | James McKinney <james@slashpoundbang.com> | 2015-05-20 16:36:51 +0200 |
commit | f2d08c8ece66f8bac867214a65ab1b7f9fe5da92 (patch) | |
tree | b23cca80ebcf4e33bb774468ca4fbf499e43f7e6 /lib/attachment_to_html/adapters/rtf.rb | |
parent | da706b6c05ee7d0be15b59cf0fdec7f6d3ed58ec (diff) |
Move common AttachmentToHTML methods to a superclass
Diffstat (limited to 'lib/attachment_to_html/adapters/rtf.rb')
-rw-r--r-- | lib/attachment_to_html/adapters/rtf.rb | 50 |
1 files changed, 3 insertions, 47 deletions
diff --git a/lib/attachment_to_html/adapters/rtf.rb b/lib/attachment_to_html/adapters/rtf.rb index 90478d9ca..4a08bf618 100644 --- a/lib/attachment_to_html/adapters/rtf.rb +++ b/lib/attachment_to_html/adapters/rtf.rb @@ -2,9 +2,9 @@ module AttachmentToHTML module Adapters # Convert application/rtf documents in to HTML - class RTF + class RTF < Adapter - attr_reader :attachment, :tmpdir + attr_reader :tmpdir # Public: Initialize a RTF converter # @@ -13,24 +13,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 @@ -45,14 +31,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 - def convert # Get the attachment body outside of the chdir call as getting # the body may require opening files too @@ -83,28 +61,6 @@ module AttachmentToHTML end html 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 |