Class: NoSE::Loader::CsvLoader

Inherits:
LoaderBase show all
Defined in:
lib/nose/loader/csv.rb

Overview

Load data into an index from a set of CSV files

Instance Method Summary collapse

Methods inherited from LoaderBase

#model, #workload

Constructor Details

#initialize(workload = nil, backend = nil) ⇒ CsvLoader

Returns a new instance of CsvLoader.



11
12
13
14
15
# File 'lib/nose/loader/csv.rb', line 11

def initialize(workload = nil, backend = nil)
  super

  @logger = Logging.logger['nose::loader::csvloader']
end

Instance Method Details

#load(indexes, config, show_progress = false, limit = nil, skip_existing = true) ⇒ Object

Load data for all the indexes



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/nose/loader/csv.rb', line 18

def load(indexes, config, show_progress = false, limit = nil,
         skip_existing = true)
  indexes.map!(&:to_id_graph).uniq! if @backend.by_id_graph

  simple_indexes = find_simple_indexes indexes, skip_existing
  simple_indexes.each do |entity, simple_index_list|
    filename = File.join config[:directory], "#{entity.name}.csv"
    total_rows = (limit || 0) - 1 # account for header row
    File.open(filename) { |file| file.each_line { total_rows += 1 } }

    progress = initialize_progress entity, simple_index_list,
                                   total_rows if show_progress
    load_file_indexes filename, entity, simple_index_list, progress
  end
end