Class: CsvGenerator
- Inherits:
-
Object
- Object
- CsvGenerator
- Defined in:
- lib/csv_generator.rb,
lib/csv_generator/version.rb
Defined Under Namespace
Classes: RowGenerator
Constant Summary collapse
- VERSION =
'1.0.0'
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(row_values) ⇒ Object
- #generate(enumerable) ⇒ Object
-
#initialize(io, options = {}) ⇒ CsvGenerator
constructor
A new instance of CsvGenerator.
Constructor Details
#initialize(io, options = {}) ⇒ CsvGenerator
Returns a new instance of CsvGenerator.
20 21 22 23 |
# File 'lib/csv_generator.rb', line 20 def initialize(io, = {}) @io = io @options = end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
4 5 6 |
# File 'lib/csv_generator.rb', line 4 def io @io end |
Class Method Details
.open(path, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/csv_generator.rb', line 7 def open(path, = {}) mode = [:mode] || 'w' = [:permission] || 0644 File.open(path, mode, ) do |io| generator = new(io, ) yield generator generator end end |
Instance Method Details
#<<(row_values) ⇒ Object
35 36 37 |
# File 'lib/csv_generator.rb', line 35 def <<(row_values) io.write row_generator.generate(row_values) end |
#generate(enumerable) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/csv_generator.rb', line 25 def generate(enumerable) enumerable.each do |row_instance| if block_given? self << (yield row_instance) else self << row_instance end end end |