Class: CsvBuilder::Streamer
- Inherits:
-
Object
- Object
- CsvBuilder::Streamer
- Defined in:
- lib/csv_builder/template_handler.rb
Overview
Streamer implements an each method to facilitate streaming back through the Rails stack. It requires the template to be passed to it as a proc. An instance of this class is returned from the template handler’s compile method, and will receive calls to each. Data is streamed by yielding back to the containing block.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(template_proc) ⇒ Streamer
constructor
A new instance of Streamer.
Constructor Details
#initialize(template_proc) ⇒ Streamer
Returns a new instance of Streamer.
78 79 80 |
# File 'lib/csv_builder/template_handler.rb', line 78 def initialize(template_proc) @template_proc = template_proc end |
Instance Method Details
#each ⇒ Object
82 83 84 85 86 87 |
# File 'lib/csv_builder/template_handler.rb', line 82 def each yielder = CsvBuilder::Yielder.new(Proc.new{|data| yield data}) csv_stream = CsvBuilder::CSV_LIB.new(yielder, @csv_options || {}) csv = CsvBuilder::TransliteratingFilter.new(csv_stream, @input_encoding || 'UTF-8', @output_encoding || 'ISO-8859-1') @template_proc.call(csv) end |