Module: NimbusRead

Defined in:
lib/nimbus_read.rb

Class Method Summary collapse

Class Method Details

.helloObject



3
4
5
# File 'lib/nimbus_read.rb', line 3

def NimbusRead.hello
  puts "Hey welcome, this is Nimbus-Read!"
end

.read_file(path, name, model_name, header_name_hash) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/nimbus_read.rb', line 8

def NimbusRead.read_file(path, name, model_name, header_name_hash)
	# header_name_hash --format--
	# { 
	#   first_name: F_NAME,
	#   last_name: L_NAME
	# }
	begin 

		path_and_name_of_csv_file = path + "/" + name
		data = []
		keys = header_name_hash.keys
		value = header_name_hash.values
		CSV.foreach(path_and_name_of_csv_file, headers: true) do |row|
      inner_data = []
      header_name_hash.each do |key,value|
        puts "row_valu: #{row[value]}    value:#{value}"
        inner_data.push(row[value])
      end
      puts "inner_data: #{inner_data}"
      data.push(inner_data)
		end
		puts "data: #{data}"

		# Uncomment following line of code, when gem is ready
		#"::#{model_name}".constantize.import keys, data, batch_size: 500
	
	rescue Exception => e
		puts 	e
	end
end