Class: Plaintext::Resolver
- Inherits:
-
Object
- Object
- Plaintext::Resolver
- Defined in:
- lib/plaintext/resolver.rb
Constant Summary collapse
- MAX_FULLTEXT_LENGTH =
4 megabytes
4_194_304
- HANDLERS =
[ Plaintext::PdfHandler, Plaintext::OpendocumentHandler, Plaintext::DocxHandler, Plaintext::XlsxHandler, Plaintext::PptxHandler, Plaintext::DocHandler, Plaintext::XlsHandler, Plaintext::PptHandler, Plaintext::ImageHandler, Plaintext::RtfHandler, Plaintext::PlaintextHandler ].freeze
Class Attribute Summary collapse
-
.cached_file_handlers ⇒ Object
Returns the value of attribute cached_file_handlers.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file, content_type = nil) ⇒ Resolver
constructor
A new instance of Resolver.
-
#text ⇒ Object
Returns the extracted fulltext or nil if no matching handler was found for the file type.
Constructor Details
#initialize(file, content_type = nil) ⇒ Resolver
Returns a new instance of Resolver.
26 27 28 29 |
# File 'lib/plaintext/resolver.rb', line 26 def initialize(file, content_type = nil) @file = file @content_type = content_type end |
Class Attribute Details
.cached_file_handlers ⇒ Object
Returns the value of attribute cached_file_handlers.
8 9 10 |
# File 'lib/plaintext/resolver.rb', line 8 def cached_file_handlers @cached_file_handlers end |
Class Method Details
.file_handlers ⇒ Object
20 21 22 23 |
# File 'lib/plaintext/resolver.rb', line 20 def file_handlers return self.cached_file_handlers if self.cached_file_handlers.present? self.cached_file_handlers = HANDLERS.map(&:new) end |
Instance Method Details
#text ⇒ Object
Returns the extracted fulltext or nil if no matching handler was found for the file type.
33 34 35 36 37 38 39 |
# File 'lib/plaintext/resolver.rb', line 33 def text if handler = find_handler and text = handler.text(@file) text.gsub! /\s+/m, ' ' text.strip! text.mb_chars.compose.limit(MAX_FULLTEXT_LENGTH).to_s end end |