Class: Redwood::Person
Overview
don’t create these by hand. rather, go through personmanager, to ensure uniqueness and overriding.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#name ⇒ Object
Returns the value of attribute name.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Class Method Summary collapse
Instance Method Summary collapse
- #better_than?(o) ⇒ Boolean
- #eql?(o) ⇒ Boolean
- #full_address ⇒ Object
-
#generic? ⇒ Boolean
heuristic: whether the name attached to this email is “real”, i.e.
- #hash ⇒ Object
-
#initialize(name, email, timestamp = 0, definitive = false) ⇒ Person
constructor
A new instance of Person.
- #longname ⇒ Object
- #mediumname ⇒ Object
-
#shortname ⇒ Object
def == o; o && o.email == email; end alias :eql? :== def hash; [name, email].hash; end.
-
#sort_by_me ⇒ Object
when sorting addresses, sort by this.
- #to_s ⇒ Object
- #touch! ⇒ Object
Constructor Details
#initialize(name, email, timestamp = 0, definitive = false) ⇒ Person
Returns a new instance of Person.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sup/person.rb', line 59 def initialize name, email, =0, definitive=false raise ArgumentError, "email can't be nil" unless email if name @name = name.gsub(/^\s+|\s+$/, "").gsub(/\s+/, " ") if @name =~ /^(['"]\s*)(.*?)(\s*["'])$/ @name = $2 end end @email = email.gsub(/^\s+|\s+$/, "").gsub(/\s+/, " ").downcase @definitive = definitive @timestamp = end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
56 57 58 |
# File 'lib/sup/person.rb', line 56 def email @email end |
#name ⇒ Object
Returns the value of attribute name.
56 57 58 |
# File 'lib/sup/person.rb', line 56 def name @name end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
56 57 58 |
# File 'lib/sup/person.rb', line 56 def @timestamp end |
Class Method Details
.from_address(s) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/sup/person.rb', line 145 def self.from_address s return nil if s.nil? ## try and parse an email address and name name, email = case s when /["'](.*?)["'] <(.*?)>/, /([^,]+) <(.*?)>/ a, b = $1, $2 [a.gsub('\"', '"'), b] when /<((\S+?)@\S+?)>/ [$2, $1] when /((\S+?)@\S+)/ [$2, $1] else [nil, s] end Person.new name, email end |
Instance Method Details
#better_than?(o) ⇒ Boolean
80 81 82 83 84 |
# File 'lib/sup/person.rb', line 80 def better_than? o return false if o.definitive? || generic? return true if definitive? o.name.nil? || (name && name.length > o.name.length && name =~ /[a-z]/) end |
#eql?(o) ⇒ Boolean
165 |
# File 'lib/sup/person.rb', line 165 def eql? o; email.eql? o.email end |
#full_address ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/sup/person.rb', line 117 def full_address if @name && @email if @name =~ /[",@]/ "#{@name.inspect} <#@email>" # escape quotes else "#@name <#@email>" end else @email end end |
#generic? ⇒ Boolean
heuristic: whether the name attached to this email is “real”, i.e. we should bother to store it.
76 77 78 |
# File 'lib/sup/person.rb', line 76 def generic? @email =~ /no\-?reply/ end |
#hash ⇒ Object
166 |
# File 'lib/sup/person.rb', line 166 def hash; email.hash end |
#longname ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/sup/person.rb', line 107 def longname if @name && @email "#@name <#@email>" else @email end end |
#mediumname ⇒ Object
115 |
# File 'lib/sup/person.rb', line 115 def mediumname; @name || @email; end |
#shortname ⇒ Object
def == o; o && o.email == email; end
alias :eql? :==
def hash; [name, email].hash; end
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/sup/person.rb', line 94 def shortname case @name when /\S+, (\S+)/ $1 when /(\S+) \S+/ $1 when nil @email else @name end end |
#sort_by_me ⇒ Object
when sorting addresses, sort by this
130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/sup/person.rb', line 130 def sort_by_me case @name when /^(\S+), \S+/ $1 when /^\S+ \S+ (\S+)/ $1 when /^\S+ (\S+)/ $1 when nil @email else @name end.downcase end |
#to_s ⇒ Object
86 |
# File 'lib/sup/person.rb', line 86 def to_s; "#@name <#@email>" end |
#touch! ⇒ Object
88 |
# File 'lib/sup/person.rb', line 88 def touch!; @timestamp = Time.now.to_i end |