Class: SpeakyCsv::Export

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/speaky_csv/export.rb

Overview

Exports records as csv. Will write a csv to the given IO object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, records_enumerator) ⇒ Export

Returns a new instance of Export.



13
14
15
16
17
18
# File 'lib/speaky_csv/export.rb', line 13

def initialize(config, records_enumerator)
  @config = config
  @records_enumerator = records_enumerator
  @log_output = StringIO.new
  @logger = Logger.new @log_output
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



11
12
13
# File 'lib/speaky_csv/export.rb', line 11

def logger
  @logger
end

Instance Method Details

#eachObject

Writes csv string to io



21
22
23
# File 'lib/speaky_csv/export.rb', line 21

def each
  block_given? ? enumerator.each { |a| yield a } : enumerator
end

#logObject

Returns a string of all the log output from the import. Or returns nothing if a custom logger was used.



27
28
29
# File 'lib/speaky_csv/export.rb', line 27

def log
  @log_output.string
end