|
|
|
@ -49,4 +49,19 @@ class Contact
|
|
|
|
|
raise ArgumentError, "Invalid telegram format: #{@telegram}" if @telegram && !valid_telegram?
|
|
|
|
|
raise ArgumentError, "Invalid email format: #{@email}" if @email && !valid_email?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.new_from_info(info_string)
|
|
|
|
|
info_string = info_string.sub(/^Contact: /, '').strip
|
|
|
|
|
|
|
|
|
|
case info_string
|
|
|
|
|
when /\APhone: (.+)\z/i
|
|
|
|
|
new(phone: Regexp.last_match(1).strip)
|
|
|
|
|
when /\ATelegram: (.+)\z/i
|
|
|
|
|
new(telegram: Regexp.last_match(1).strip)
|
|
|
|
|
when /\AEmail: (.+)\z/i
|
|
|
|
|
new(email: Regexp.last_match(1).strip)
|
|
|
|
|
else
|
|
|
|
|
raise ArgumentError, "Invalid contact info format: #{info_string}"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|