Class: CSVImporter::Importer

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_importer/csv_importer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str_or_readable, klass = nil, dictionary = {}) ⇒ Importer

Returns a new instance of Importer.



9
10
11
12
13
14
15
16
17
# File 'lib/csv_importer/csv_importer.rb', line 9

def initialize(str_or_readable, klass=nil, dictionary={})
  @klass = klass
  @save = save
  @dictionary = {}
  dictionary.each_pair{|k,v| @dictionary[k.downcase] = v.downcase}
  @delimiter, @csv_columns = determine_delimiter_and_columns(str_or_readable)
  @columns = match_columns
  @reader = CSV::Reader.create(str_or_readable, @delimiter)
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



7
8
9
# File 'lib/csv_importer/csv_importer.rb', line 7

def columns
  @columns
end

#csv_columnsObject (readonly)

Returns the value of attribute csv_columns.



7
8
9
# File 'lib/csv_importer/csv_importer.rb', line 7

def csv_columns
  @csv_columns
end

#delimiterObject (readonly)

Returns the value of attribute delimiter.



7
8
9
# File 'lib/csv_importer/csv_importer.rb', line 7

def delimiter
  @delimiter
end

#dictionaryObject (readonly)

Returns the value of attribute dictionary.



7
8
9
# File 'lib/csv_importer/csv_importer.rb', line 7

def dictionary
  @dictionary
end

#klassObject (readonly)

Returns the value of attribute klass.



7
8
9
# File 'lib/csv_importer/csv_importer.rb', line 7

def klass
  @klass
end

#objects(save = false) ⇒ Object (readonly)

Returns the value of attribute objects.



7
8
9
# File 'lib/csv_importer/csv_importer.rb', line 7

def objects
  @objects
end

#readerObject (readonly)

Returns the value of attribute reader.



7
8
9
# File 'lib/csv_importer/csv_importer.rb', line 7

def reader
  @reader
end

#saveObject (readonly)

Returns the value of attribute save.



7
8
9
# File 'lib/csv_importer/csv_importer.rb', line 7

def save
  @save
end