Class: Legion::Data::Extract::Handlers::Base
- Inherits:
-
Object
- Object
- Legion::Data::Extract::Handlers::Base
show all
- Defined in:
- lib/legion/data/extract/handlers/base.rb
Direct Known Subclasses
Csv, Docx, Html, Json, Jsonl, Markdown, Pdf, Pptx, Text, Vtt, Xlsx
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.registry ⇒ Object
Returns the value of attribute registry.
11
12
13
|
# File 'lib/legion/data/extract/handlers/base.rb', line 11
def registry
@registry
end
|
Class Method Details
.available? ⇒ Boolean
45
46
47
48
49
50
51
52
|
# File 'lib/legion/data/extract/handlers/base.rb', line 45
def available?
return true if gem_name.nil?
require gem_name
true
rescue LoadError
false
end
|
.extensions ⇒ Object
38
|
# File 'lib/legion/data/extract/handlers/base.rb', line 38
def extensions = []
|
41
42
43
|
# File 'lib/legion/data/extract/handlers/base.rb', line 41
def (_source)
raise NotImplementedError, "#{name} must implement .extract"
end
|
.for_type(type) ⇒ Object
28
29
30
|
# File 'lib/legion/data/extract/handlers/base.rb', line 28
def for_type(type)
@registry[type&.to_sym]
end
|
.gem_name ⇒ Object
39
|
# File 'lib/legion/data/extract/handlers/base.rb', line 39
def gem_name = nil
|
.inherited(subclass) ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/legion/data/extract/handlers/base.rb', line 13
def inherited(subclass)
super
TracePoint.new(:end) do |tp|
if tp.self == subclass
register(subclass) if subclass.respond_to?(:type) && subclass.type
tp.disable
end
end.enable
end
|
.register(handler_class) ⇒ Object
24
25
26
|
# File 'lib/legion/data/extract/handlers/base.rb', line 24
def register(handler_class)
@registry = @registry.merge(handler_class.type => handler_class).freeze
end
|
.supported_types ⇒ Object
32
33
34
|
# File 'lib/legion/data/extract/handlers/base.rb', line 32
def supported_types
@registry.keys
end
|
.type ⇒ Object
37
|
# File 'lib/legion/data/extract/handlers/base.rb', line 37
def type = nil
|