Class: Legion::Data::Extract::Handlers::Json
- Inherits:
-
Base
- Object
- Base
- Legion::Data::Extract::Handlers::Json
show all
- Defined in:
- lib/legion/data/extract/handlers/json.rb
Class Method Summary
collapse
Methods inherited from Base
available?, for_type, inherited, register, supported_types
#handle_exception
Class Method Details
.extensions ⇒ Object
11
|
# File 'lib/legion/data/extract/handlers/json.rb', line 11
def self.extensions = %w[.json]
|
14
15
16
17
18
19
20
21
22
|
# File 'lib/legion/data/extract/handlers/json.rb', line 14
def self.(source)
content = source.respond_to?(:read) ? source.read : File.read(source.to_s)
parsed = ::JSON.parse(content)
text = ::JSON.pretty_generate(parsed)
{ text: text, metadata: { keys: parsed.is_a?(Hash) ? parsed.keys : nil } }
rescue StandardError => e
handle_exception(e, level: :warn, handled: true, operation: :extract_json)
{ text: nil, error: e.message }
end
|
.gem_name ⇒ Object
12
|
# File 'lib/legion/data/extract/handlers/json.rb', line 12
def self.gem_name = nil
|
.type ⇒ Object
10
|
# File 'lib/legion/data/extract/handlers/json.rb', line 10
def self.type = :json
|