blob: b0d974148abdc6b26400548054a9d7ea65108bd7 (
plain)
1
2
3
4
5
6
7
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
|
require 'csv'
class AuthorsImporter
def initialize path
if File.exists? path
@parsed_file = CSV::Reader.parse(File.open(path, "r"))
else
raise "File does not exist"
end
end
def import_authors
@parsed_file.each do |row|
password = generate_password
options = {
:login => row[0],
:full_name => row[1],
:email => row[2],
:password => password,
:password_confirmation => password
}
unless user = User.find_by_email(options[:email])
User.create options
end
end
end
def generate_password
Digest::SHA1.hexdigest("#{Time.now+rand(10000).days}")
end
end
|