Class: Paperclip::Document::Processors::Counter
- Inherits:
-
Paperclip::Document::Processor
- Object
- Processor
- Paperclip::Document::Processor
- Paperclip::Document::Processors::Counter
- Defined in:
- lib/paperclip/document/processors/counter.rb
Overview
This processor extract the OCR text of the file
Instance Attribute Summary collapse
-
#pages_count_column ⇒ Object
Returns the value of attribute pages_count_column.
Attributes inherited from Paperclip::Document::Processor
Instance Method Summary collapse
-
#default_pages_count_column ⇒ Object
Returns the name of the default pages count column.
-
#initialize(file, options = {}, attachment = nil) ⇒ Counter
constructor
A new instance of Counter.
-
#make ⇒ Object
Extract the pages count of all the document.
-
#pages_count_column? ⇒ Boolean
Check if a pages count column is present.
Methods inherited from Paperclip::Document::Processor
Constructor Details
#initialize(file, options = {}, attachment = nil) ⇒ Counter
Returns a new instance of Counter.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/paperclip/document/processors/counter.rb', line 8 def initialize(file, = {}, = nil) super(file, , ) if @options[:pages_count_column].nil? && pages_count_column? @options[:pages_count_column] = default_pages_count_column end @pages_count_column = @options[:pages_count_column] unless @pages_count_column raise Paperclip::Error, 'No pages count column given' end end |
Instance Attribute Details
#pages_count_column ⇒ Object
Returns the value of attribute pages_count_column.
6 7 8 |
# File 'lib/paperclip/document/processors/counter.rb', line 6 def pages_count_column @pages_count_column end |
Instance Method Details
#default_pages_count_column ⇒ Object
Returns the name of the default pages count column
39 40 41 |
# File 'lib/paperclip/document/processors/counter.rb', line 39 def default_pages_count_column @attachment.name.to_s + '_pages_count' end |
#make ⇒ Object
Extract the pages count of all the document
21 22 23 24 25 26 27 28 |
# File 'lib/paperclip/document/processors/counter.rb', line 21 def make count = Docsplit.extract_length(file_path.to_s) instance[pages_count_column] = count instance.run_callbacks(:save) { false } File.open(file.path) end |
#pages_count_column? ⇒ Boolean
Check if a pages count column is present
31 32 33 34 35 36 |
# File 'lib/paperclip/document/processors/counter.rb', line 31 def pages_count_column? expected_column = default_pages_count_column @attachment.instance.class.columns.detect do |column| column.name.to_s == expected_column end end |