summaryrefslogtreecommitdiff
path: root/lib/authors_importer.rb
diff options
context:
space:
mode:
authorerdgeist <erdgeist@dyn-174.club.berlin.ccc.de>2009-04-09 20:13:30 +0200
committererdgeist <erdgeist@dyn-174.club.berlin.ccc.de>2009-04-09 20:13:30 +0200
commit44e1eff0155d3da825ae7f4ef9e334a8e231e909 (patch)
treee6d21e4d0b8464ac9febb9efacc68cabe321a9c6 /lib/authors_importer.rb
parent8c6b4dcf08268ed2971b06df40c733ba28448582 (diff)
parentacc9301696de3589a17d1543a7ab3fc1914e8ce8 (diff)
Merge branch 'master' of ssh://git@svn.medienhaus.udk-berlin.de/usr/local/git/cccms
Diffstat (limited to 'lib/authors_importer.rb')
-rw-r--r--lib/authors_importer.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/authors_importer.rb b/lib/authors_importer.rb
new file mode 100644
index 0000000..b0d9741
--- /dev/null
+++ b/lib/authors_importer.rb
@@ -0,0 +1,35 @@
1require 'csv'
2
3
4class AuthorsImporter
5
6 def initialize path
7 if File.exists? path
8 @parsed_file = CSV::Reader.parse(File.open(path, "r"))
9 else
10 raise "File does not exist"
11 end
12 end
13
14 def import_authors
15 @parsed_file.each do |row|
16 password = generate_password
17
18 options = {
19 :login => row[0],
20 :full_name => row[1],
21 :email => row[2],
22 :password => password,
23 :password_confirmation => password
24 }
25
26 unless user = User.find_by_email(options[:email])
27 User.create options
28 end
29 end
30 end
31
32 def generate_password
33 Digest::SHA1.hexdigest("#{Time.now+rand(10000).days}")
34 end
35end \ No newline at end of file