class ContactsTxtAgent
Public Instance Methods
find_mobile_by_name(s)
click to toggle source
# File lib/contacts_txt.rb, line 265 def find_mobile_by_name(s) result = find_by_name(s) r = validate(result) numbers = [r.sms.empty? ? r.mobile : r.sms, r.mobile].uniq\ .map {|x| x.sub(/\([^\)]+\)/,'').strip} h = {} h[:msg] = if numbers.length > 1 then "The SMS number for %s is %s and the mobile number is %s" % \ [r.fullname, *numbers] elsif numbers.first.length > 0 then "The mobile number for %s is %s" % [r.fullname, numbers.first] elsif r.tel.length > 0 then "I don't have a mobile number, but the landline telephone " + \ "number for %s is %s" % [r.fullname, r.tel] else "I don't have a telephone number for " + r.fullname end h[:tags] = r.tags.to_s h end
find_tel_by_name(s)
click to toggle source
# File lib/contacts_txt.rb, line 291 def find_tel_by_name(s) result = find_by_name(s) r = validate(result) h = {} if r.tel.empty? then return find_mobile_by_name(s) else h[:msg] = "The telephone number for %s is %s" % [r.fullname, r.tel] end h[:tags] = r.tags.to_s h end
Private Instance Methods
validate(result)
click to toggle source
# File lib/contacts_txt.rb, line 310 def validate(result) case result.class.to_s when 'RecordX' result when 'Array' result.first when 'NilClass' return "I couldn't find that name." end end