Class: Redwood::ContactManager
- Includes:
- Singleton
- Defined in:
- lib/sup/contact.rb
Instance Method Summary collapse
- #alias_for(person) ⇒ Object
- #contact_for(aalias) ⇒ Object
- #contacts ⇒ Object
- #contacts_with_aliases ⇒ Object
-
#drop_contact(person) ⇒ Object
this may not actually be called anywhere, since we still keep contacts around without aliases to override any fullname changes.
-
#initialize(fn) ⇒ ContactManager
constructor
A new instance of ContactManager.
- #is_aliased_contact?(person) ⇒ Boolean
- #person_for(email) ⇒ Object
- #save ⇒ Object
- #update_alias(person, aalias = nil) ⇒ Object
Methods included from Singleton
Constructor Details
#initialize(fn) ⇒ ContactManager
Returns a new instance of ContactManager.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sup/contact.rb', line 8 def initialize fn @fn = fn ## maintain the mapping between people and aliases. for contacts without ## aliases, there will be no @a2p entry, so @p2a.keys should be treated ## as the canonical list of contacts. @p2a = {} # person to alias @a2p = {} # alias to person @e2p = {} # email to person if File.exists? fn IO.foreach(fn) do |l| l =~ /^([^:]*): (.*)$/ or raise "can't parse #{fn} line #{l.inspect}" aalias, addr = $1, $2 update_alias Person.from_address(addr), aalias end end end |
Instance Method Details
#alias_for(person) ⇒ Object
54 |
# File 'lib/sup/contact.rb', line 54 def alias_for person; @p2a[person] end |
#contact_for(aalias) ⇒ Object
53 |
# File 'lib/sup/contact.rb', line 53 def contact_for aalias; @a2p[aalias] end |
#contacts ⇒ Object
28 |
# File 'lib/sup/contact.rb', line 28 def contacts; @p2a.keys end |
#contacts_with_aliases ⇒ Object
29 |
# File 'lib/sup/contact.rb', line 29 def contacts_with_aliases; @a2p.values.uniq end |
#drop_contact(person) ⇒ Object
this may not actually be called anywhere, since we still keep contacts around without aliases to override any fullname changes.
46 47 48 49 50 51 |
# File 'lib/sup/contact.rb', line 46 def drop_contact person aalias = @p2a[person] @p2a.delete person @e2p.delete person.email @a2p.delete aalias if aalias end |
#is_aliased_contact?(person) ⇒ Boolean
56 |
# File 'lib/sup/contact.rb', line 56 def is_aliased_contact? person; !@p2a[person].nil? end |
#person_for(email) ⇒ Object
55 |
# File 'lib/sup/contact.rb', line 55 def person_for email; @e2p[email] end |
#save ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/sup/contact.rb', line 58 def save File.open(@fn, "w:UTF-8") do |f| @p2a.sort_by { |(p, a)| [p.full_address, a] }.each do |(p, a)| f.puts "#{a || ''}: #{p.full_address}" end end end |
#update_alias(person, aalias = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sup/contact.rb', line 31 def update_alias person, aalias=nil old_aalias = @p2a[person] if(old_aalias != nil and old_aalias != "") # remove old alias @a2p.delete old_aalias @e2p.delete person.email end @p2a[person] = aalias unless aalias.nil? || aalias.empty? @a2p[aalias] = person @e2p[person.email] = person end end |