Class: Xommelier::RSS::EmailAddress

Inherits:
String
  • Object
show all
Defined in:
lib/xommelier/rss.rb

Overview

The RECOMMENDED format for e-mail addresses in RSS elements is: [email protected] (Real Name) http://www.rssboard.org/rss-profile#data-types-email

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_xommelier(string) ⇒ Object



19
20
21
22
23
# File 'lib/xommelier/rss.rb', line 19

def self.from_xommelier(string)
  email = new(string)
  email.name?
  email
end

Instance Method Details

#addressObject



39
40
41
# File 'lib/xommelier/rss.rb', line 39

def address
  to_s
end

#address=(address) ⇒ Object



43
44
45
# File 'lib/xommelier/rss.rb', line 43

def address=(address)
  replace(address)
end

#nameObject



47
48
49
# File 'lib/xommelier/rss.rb', line 47

def name
  @name if name?
end

#name=(name) ⇒ Object



51
52
53
54
# File 'lib/xommelier/rss.rb', line 51

def name=(name)
  @has_name = name.present?
  @name = name
end

#name?Boolean

Returns:



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/xommelier/rss.rb', line 25

def name?
  @has_name ||= begin
    address, name = strip.split(/\s+/, 2)

    if name.present? && name =~ /\(([\w ]+)\)\s?/
      replace(address)
      @name = Regexp.last_match(1).to_s
      true
    else
      false
    end
  end
end

#to_xommelierObject



56
57
58
59
60
61
62
# File 'lib/xommelier/rss.rb', line 56

def to_xommelier
  if name?
    "#{address} (#{name})"
  else
    address
  end
end