Class: Paperclip::DocsplitText

Inherits:
DocsplitProcessor show all
Defined in:
lib/processors/docsplit_text.rb

Instance Attribute Summary

Attributes inherited from DocsplitProcessor

#attachment, #options, #src

Instance Method Summary collapse

Methods inherited from DocsplitProcessor

#initialize, #src_path

Constructor Details

This class inherits a constructor from Paperclip::DocsplitProcessor

Instance Method Details

#destination_fileObject



28
29
30
# File 'lib/processors/docsplit_text.rb', line 28

def destination_file
  File.open(File.join(@dst_path, "#{@basename}.txt"))
end

#full_textObject



32
33
34
35
36
37
38
39
40
# File 'lib/processors/docsplit_text.rb', line 32

def full_text
  full_text = String.new

  destination_file.each do |line|
    full_text += line
  end

  full_text
end

#makeObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/processors/docsplit_text.rb', line 3

def make
  begin
    @dst_path = Dir.tmpdir
    @pages    = @options[:pages] || [1]
    @options  = @options.merge(:output => @dst_path)

    Docsplit.extract_text(src_path, @options)
  rescue Exception => e
    raise Paperclip::Error, "There was an error extracting text from #{@basename}"
  end

  if @options[:full_text_column]
    # Bypassing callbacks to save full text. See Paperclip issue #671:
    # https://github.com/thoughtbot/paperclip/issues/671
    ar_model = @attachment.instance
    ar_model[@options[:full_text_column]] = full_text
    ar_model.run_callbacks(:save) { false }

    # This would be the preferred method of saving this text.
    # @attachment.instance.update_attribute(@options[:full_text_column], full_text)
  end

  destination_file
end