]> git.notmuchmail.org Git - sup/commitdiff
keeping track of last access times in people.txt now so that we can start
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Thu, 28 Dec 2006 23:23:31 +0000 (23:23 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Thu, 28 Dec 2006 23:23:31 +0000 (23:23 +0000)
trimming this file when it gets too big

git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@114 5c8cc53c-5e98-4d25-b20a-d8db53a31250

lib/sup/person.rb

index 206885b5c8c1d97a164ae084a775f9c5b3b92b3e..6640739927261114bddf75f76a77d42461ee3b2b 100644 (file)
@@ -6,11 +6,11 @@ class PersonManager
   def initialize fn
     @fn = fn
     @names = {}
-    IO.readlines(fn).map { |l| l =~ /^(.*)?:\s+(.*)$/ && @names[$1] = $2 } if File.exists? fn
+    IO.readlines(fn).map { |l| l =~ /^(.*)?:\s+(\d+)\s+(.*)$/ && @names[$1] = [$2.to_i, $3] } if File.exists? fn
     self.class.i_am_the_instance self
   end
 
-  def name_for email; @names[email]; end
+  def name_for email; @names[email][1]; end
   def register email, name
     return unless name
 
@@ -18,11 +18,12 @@ class PersonManager
 
     ## all else being equal, prefer longer names, unless the prior name
     ## doesn't contain any capitalization
-    oldname = @names[email]
-    @names[email] = name if oldname.nil? || oldname.length < name.length || (oldname !~ /[A-Z]/ && name =~ /[A-Z]/)
+    oldcount, oldname = @names[email]
+    @names[email] = [0, name] if oldname.nil? || oldname.length < name.length || (oldname !~ /[A-Z]/ && name =~ /[A-Z]/)
+    @names[email][0] = Time.now.to_i
   end
 
-  def save; File.open(@fn, "w") { |f| @names.each { |email, name| f.puts "#{email}: #{name}" } }; end
+  def save; File.open(@fn, "w") { |f| @names.each { |email, (time, name)| f.puts "#{email}: #{time} #{name}" } }; end
 end
 
 class Person