Class: Lutaml::KeyValue::Adapter::Jsonl::StandardAdapter
- Inherits:
-
Document
- Object
- Document
- Lutaml::KeyValue::Adapter::Jsonl::StandardAdapter
show all
- Defined in:
- lib/lutaml/key_value/adapter/jsonl/standard_adapter.rb
Constant Summary
collapse
- FORMAT_SYMBOL =
:jsonl
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Document
#initialize
Class Method Details
.parse(jsonl, _options = {}) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/lutaml/key_value/adapter/jsonl/standard_adapter.rb', line 12
def self.parse(jsonl, _options = {})
results = []
jsonl.split("\n").each do |line|
next if line.strip.empty?
begin
results << JSON.parse(line, create_additions: false)
rescue JSON::ParserError => e
warn "Skipping invalid line: #{e.message}"
end
end
results
end
|
Instance Method Details
#to_jsonl(*_args) ⇒ Object
27
28
29
30
31
|
# File 'lib/lutaml/key_value/adapter/jsonl/standard_adapter.rb', line 27
def to_jsonl(*_args)
(@jsons || []).map do |json|
JSON.generate(json)
end.join("\n")
end
|