Class: CsvGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_generator.rb,
lib/csv_generator/version.rb

Defined Under Namespace

Classes: RowGenerator

Constant Summary collapse

VERSION =
'0.5.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ CsvGenerator

Returns a new instance of CsvGenerator.



24
25
26
# File 'lib/csv_generator.rb', line 24

def initialize(io)
  @io = io
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



4
5
6
# File 'lib/csv_generator.rb', line 4

def io
  @io
end

Class Method Details

.generate(path, options = {}, &block) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/csv_generator.rb', line 7

def generate(path, options = {}, &block)
  mode = options[:mode] || 'w'
  permission = options[:permission] || 0644

  File.open(path, mode, permission) do |io|
    with io, &block
  end
end

.with(io) {|generator| ... } ⇒ Object

Yields:

  • (generator)


16
17
18
19
20
21
# File 'lib/csv_generator.rb', line 16

def with(io)
  generator = new(io)

  yield generator if block_given?
  generator
end

Instance Method Details

#<<(row_values) ⇒ Object



28
29
30
# File 'lib/csv_generator.rb', line 28

def <<(row_values)
  io.write row_generator.generate(row_values)
end