diff options
| author | hukl <contact@smyck.org> | 2009-04-07 21:53:49 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-04-07 21:53:49 +0200 |
| commit | 9d2d5d68ddc523149c2f2870017ee459b670d879 (patch) | |
| tree | 78d7186692f982298fd619c728ed2cb0dc7d6110 /lib | |
| parent | 72a1e956d116bd5ebca528906e4b92dba5488474 (diff) | |
adding authors_importer.rb
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/authors_importer.rb | 35 |
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 @@ | |||
| 1 | require 'csv' | ||
| 2 | |||
| 3 | |||
| 4 | class 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 | ||
| 35 | end \ No newline at end of file | ||
