From 9d2d5d68ddc523149c2f2870017ee459b670d879 Mon Sep 17 00:00:00 2001 From: hukl Date: Tue, 7 Apr 2009 21:53:49 +0200 Subject: adding authors_importer.rb --- lib/authors_importer.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/authors_importer.rb (limited to 'lib') 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 @@ +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 \ No newline at end of file -- cgit v1.3