Class: SpeakyCsv::AttrImport

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

Overview

Imports a csv file as attribute hashes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, input_io) ⇒ AttrImport

Returns a new instance of AttrImport.



11
12
13
14
15
16
# File 'lib/speaky_csv/attr_import.rb', line 11

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

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



9
10
11
# File 'lib/speaky_csv/attr_import.rb', line 9

def logger
  @logger
end

Instance Method Details

#eachObject

Yields successive attribute hashes for rows in the csv file



19
20
21
# File 'lib/speaky_csv/attr_import.rb', line 19

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.



25
26
27
# File 'lib/speaky_csv/attr_import.rb', line 25

def log
  @log_output.string
end