Class: JSONSEQ::Writer
- Inherits:
-
Object
- Object
- JSONSEQ::Writer
- Defined in:
- lib/jsonseq/writer.rb
Constant Summary collapse
- DEFAULT_ENCODER =
-> (object) { JSON.dump(object) }
Instance Attribute Summary collapse
-
#encoder ⇒ Object
readonly
Returns the value of attribute encoder.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
- #<<(object) ⇒ Object
-
#initialize(io:, encoder: DEFAULT_ENCODER) ⇒ Writer
constructor
A new instance of Writer.
- #write(object) ⇒ Object
Constructor Details
#initialize(io:, encoder: DEFAULT_ENCODER) ⇒ Writer
Returns a new instance of Writer.
8 9 10 11 |
# File 'lib/jsonseq/writer.rb', line 8 def initialize(io:, encoder: DEFAULT_ENCODER) @io = io @encoder = encoder end |
Instance Attribute Details
#encoder ⇒ Object (readonly)
Returns the value of attribute encoder.
6 7 8 |
# File 'lib/jsonseq/writer.rb', line 6 def encoder @encoder end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
5 6 7 |
# File 'lib/jsonseq/writer.rb', line 5 def io @io end |
Instance Method Details
#<<(object) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/jsonseq/writer.rb', line 13 def <<(object) io.write RS io.write encoder[object] io.write LF io.flush end |
#write(object) ⇒ Object
20 21 22 |
# File 'lib/jsonseq/writer.rb', line 20 def write(object) self << object end |