Class: Legion::Data::Extract::Handlers::Text

Inherits:
Base
  • Object
show all
Defined in:
lib/legion/data/extract/handlers/text.rb

Class Method Summary collapse

Methods inherited from Base

available?, for_type, inherited, register, supported_types

Methods included from Logging::Helper

#handle_exception

Class Method Details

.extensionsObject



9
# File 'lib/legion/data/extract/handlers/text.rb', line 9

def self.extensions = %w[.txt]

.extract(source) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/legion/data/extract/handlers/text.rb', line 12

def self.extract(source)
  content = source.respond_to?(:read) ? source.read : File.read(source.to_s)
  { text: content, metadata: { bytes: content.bytesize } }
rescue StandardError => e
  handle_exception(e, level: :warn, handled: true, operation: :extract_text)
  { text: nil, error: e.message }
end

.gem_nameObject



10
# File 'lib/legion/data/extract/handlers/text.rb', line 10

def self.gem_name = nil

.typeObject



8
# File 'lib/legion/data/extract/handlers/text.rb', line 8

def self.type = :text