Module: TWPipeline::Jsonl
- Defined in:
- lib/twpipeline/jsonl.rb,
sig/twpipeline.rbs
Class Method Summary collapse
- .dump(record) ⇒ Object
- .each(io) ⇒ Object
- .parse(line) ⇒ Object
- .wrap(text, source: "stdin", index: 0) ⇒ Object
Instance Method Summary collapse
- #self?.dump ⇒ ::String
- #self?.each {|arg0| ... } ⇒ Object
- #self?.parse ⇒ record
- #self?.wrap ⇒ record
Class Method Details
.dump(record) ⇒ Object
15 |
# File 'lib/twpipeline/jsonl.rb', line 15 def dump(record) = JSON.generate(record) |
.each(io) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/twpipeline/jsonl.rb', line 17 def each(io) return to_enum(:each, io) unless block_given? io.each_line do |line| stripped = line.strip yield parse(stripped) unless stripped.empty? end end |
.parse(line) ⇒ Object
9 10 11 12 13 |
# File 'lib/twpipeline/jsonl.rb', line 9 def parse(line) JSON.parse(line, symbolize_names: true) rescue JSON::ParserError => error raise Error, "malformed JSONL: #{error.}" end |
.wrap(text, source: "stdin", index: 0) ⇒ Object
26 27 28 |
# File 'lib/twpipeline/jsonl.rb', line 26 def wrap(text, source: "stdin", index: 0) {id: "#{source}:#{index}", source: source, text: text, ok: true, findings: []} end |
Instance Method Details
#self?.dump ⇒ ::String
51 |
# File 'sig/twpipeline.rbs', line 51
def self?.dump: (record) -> ::String
|
#self? ⇒ void #self? ⇒ ::Enumerator[record, void]
52 53 |
# File 'sig/twpipeline.rbs', line 52
def self?.each: (untyped io) { (record) -> void } -> void
| (untyped io) -> ::Enumerator[record, void]
|
#self?.parse ⇒ record
50 |
# File 'sig/twpipeline.rbs', line 50
def self?.parse: (::String line) -> record
|
#self?.wrap ⇒ record
54 |
# File 'sig/twpipeline.rbs', line 54
def self?.wrap: (::String text, ?source: ::String, ?index: ::Integer) -> record
|