Top Level Namespace
Defined Under Namespace
Modules: AccountHelper, ApplicationHelper, Localization, Localizer, LoginSystem, PersonHelper, SubscriberHelper, UserSystem
Classes: AccountController, Choice, Elt, EltController, Mail, MailNotify, Mailman, OldVisit, Person, PersonController, PersonMail, PersonNotify, SubscriberController, Subscription, User, UserNotify, Visit
Constant Summary
collapse
- ICONV =
Iconv.new 'UTF-8', 'ISO-8859-15'
Instance Method Summary
collapse
Instance Method Details
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/data_import.rb', line 10
def inputDir(directory)
Dir.glob(directory+'/*.txt') do |file|
dir = directory+'/'+file
inputFile File.basename(directory), file
end
Dir.foreach(directory) do |d|
if (d != '.' and d != '..' and d != '.svn')
dir = directory+'/'+d
if (File.directory?(dir) or File.symlink?(dir))
inputDir dir
end
end
end
end
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/data_import.rb', line 27
def inputFile(d, fileName)
puts 'Loading: '+File.basename(fileName).gsub(/.txt/, '')
elt = Elt.find_by_id File.basename(fileName).gsub(/.txt/, '')
elt ||= Elt.new :id => File.basename(fileName).gsub(/.txt/, ''), :created_on => nil
file = File.new fileName
if !elt.created_on or elt.created_on < file.mtime
elt.mail = nil
elt.parent_id = d
elt.created_on = file.mtime
puts elt.created_on.class
elt.subject = ICONV.iconv(file.gets.strip)
elt.body = format(ICONV.iconv(file.gets('\n')))
puts "subject: #{elt.subject} (created_on: #{elt.created_on.to_s})"
elt.save
elt.parent.add_child elt unless elt.lft or elt.rgt
end
end
|