Class: FlatKit::Jsonl::Writer
- Defined in:
- lib/flat_kit/jsonl/writer.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Attributes inherited from Writer
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(destination:) ⇒ Writer
constructor
A new instance of Writer.
- #write(record) ⇒ Object
- #write_record(record) ⇒ Object
Methods inherited from Writer
create_writer_from_path, #format_name
Constructor Details
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
5 6 7 |
# File 'lib/flat_kit/jsonl/writer.rb', line 5 def count @count end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
4 5 6 |
# File 'lib/flat_kit/jsonl/writer.rb', line 4 def output @output end |
Class Method Details
.format_name ⇒ Object
7 8 9 |
# File 'lib/flat_kit/jsonl/writer.rb', line 7 def self.format_name ::FlatKit::Jsonl::Format.format_name end |
Instance Method Details
#close ⇒ Object
34 35 36 |
# File 'lib/flat_kit/jsonl/writer.rb', line 34 def close @output.close end |
#write(record) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/flat_kit/jsonl/writer.rb', line 17 def write(record) case record when FlatKit::Jsonl::Record write_record(record) when FlatKit::Record converted_record = ::FlatKit::Jsonl::Record.from_record(record) write_record(converted_record) else raise FlatKit::Error, "Unable to write records of type #{record.class}" end rescue FlatKit::Error => fe raise fe rescue => e ::FlatKit.logger.error "Error reading jsonl records from #{output.name}: #{e}" raise ::FlatKit::Error, e end |
#write_record(record) ⇒ Object
38 39 40 41 42 |
# File 'lib/flat_kit/jsonl/writer.rb', line 38 def write_record(record) # enforces ending in newlin if it doesn't already have one output.io.puts record.to_s @count += 1 end |