Class: Howlr::Message::Recipient

Inherits:
Object
  • Object
show all
Defined in:
lib/howlr/message.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deliverer, address) ⇒ Recipient

Returns a new instance of Recipient.



152
153
154
155
# File 'lib/howlr/message.rb', line 152

def initialize(deliverer, address)
  @deliverer = deliverer
  @address = address
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



150
151
152
# File 'lib/howlr/message.rb', line 150

def address
  @address
end

#delivererObject

Returns the value of attribute deliverer.



150
151
152
# File 'lib/howlr/message.rb', line 150

def deliverer
  @deliverer
end

Class Method Details

.parse(raw) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/howlr/message.rb', line 158

def self.parse(raw)
  return nil if raw.nil?
  
  raw =~ /^(?:(\w*):)?(.*)/
  
  if $~[1]
    protocol = $~[1].intern
    address = $~[2]
  elsif $~
    protocol = :mailto
    address = raw
  else
    raise ArgumentError, "#{raw.inspect} is not a valid address."
  end
  
  $LOG.debug "Parsing raw recipient: #{raw.inspect} --> protocol: #{protocol.inspect}, address: #{address.inspect}"
  
  case protocol
  when :mailto
    deliverer = Howlr::Deliverers::Email
  else
    raise ArgumentError, "#{protocol.inspect} is not a valid delivery protocol!"
  end
  
  return Recipient.new(deliverer, address)
end

Instance Method Details

#to_sObject



185
186
187
# File 'lib/howlr/message.rb', line 185

def to_s
  "#{deliverer.protocol}:#{address}"
end

#to_xml(options = {}) ⇒ Object



189
190
191
192
193
194
195
# File 'lib/howlr/message.rb', line 189

def to_xml(options = {})
  if b = options[:builder]
    b.recipient to_s
  else
    "<recipient>#{to_s}</recipient>"
  end
end