Class: Redwood::PersonManager
- Includes:
- Singleton
- Defined in:
- lib/sup/person.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(fn) ⇒ PersonManager
constructor
A new instance of PersonManager.
- #save ⇒ Object
Constructor Details
#initialize(fn) ⇒ PersonManager
Returns a new instance of PersonManager.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/sup/person.rb', line 6 def initialize fn @fn = fn @@people = {} ## read in stored people IO.readlines(fn).map do |l| l =~ /^(.*)?:\s+(\d+)\s+(.*)$/ or raise "can't parse: #{l}" email, time, name = $1, $2, $3 @@people[email] = Person.new name, email, time, false end if File.exists? fn self.class.i_am_the_instance self end |
Class Method Details
.people_for(s, opts = {}) ⇒ Object
30 31 32 33 |
# File 'lib/sup/person.rb', line 30 def self.people_for s, opts={} return [] if s.nil? s.split_on_commas.map { |ss| self.person_for ss, opts } end |
.person_for(s, opts = {}) ⇒ Object
35 36 37 38 39 |
# File 'lib/sup/person.rb', line 35 def self.person_for s, opts={} p = Person.from_address(s) or return nil p.definitive = true if opts[:definitive] register p end |
.register(p) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sup/person.rb', line 41 def self.register p oldp = @@people[p.email] if oldp.nil? || p.better_than?(oldp) @@people[p.email] = p end @@people[p.email].touch! @@people[p.email] end |
Instance Method Details
#save ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/sup/person.rb', line 20 def save File.open(@fn, "w") do |f| @@people.each do |email, p| next if p.email == p.name next if p.email =~ /=/ # drop rfc2047-encoded, and lots of other useless emails. definitely a heuristic. f.puts "#{p.email}: #{p.} #{p.name}" end end end |