Class: CSVRb::StreamBuilder
- Inherits:
-
Object
- Object
- CSVRb::StreamBuilder
show all
- Defined in:
- lib/csv_rb/stream_builder.rb
Instance Method Summary
collapse
Constructor Details
#initialize(enumerator, with_compression = true) ⇒ StreamBuilder
Returns a new instance of StreamBuilder.
3
4
5
6
7
|
# File 'lib/csv_rb/stream_builder.rb', line 3
def initialize(enumerator, with_compression = true)
@enumerator = enumerator
@with_compression = with_compression
@deflator = Zlib::Deflate.new if @with_compression
end
|
Instance Method Details
#<<(row) ⇒ Object
23
24
25
|
# File 'lib/csv_rb/stream_builder.rb', line 23
def <<(row)
stream(row)
end
|
#close ⇒ Object
27
28
29
|
# File 'lib/csv_rb/stream_builder.rb', line 27
def close
y << @deflator.flush(Zlib::FINISH) if @with_compression
end
|
#set(value) ⇒ Object
13
14
15
|
# File 'lib/csv_rb/stream_builder.rb', line 13
def set(value)
y << compress(value)
end
|
#stream(row) ⇒ Object
17
18
19
20
21
|
# File 'lib/csv_rb/stream_builder.rb', line 17
def stream(row)
y << compress(
CSV.generate_line(row, force_quotes: true, encoding: 'utf-8')
)
end
|
#y ⇒ Object
9
10
11
|
# File 'lib/csv_rb/stream_builder.rb', line 9
def y
@enumerator
end
|