class Ppl::Service::PhoneNumber

Attributes

storage[W]

Public Instance Methods

add(contact, number, options) click to toggle source
# File lib/ppl/service/phone_number.rb, line 5
def add(contact, number, options)
  phone_number = Ppl::Entity::PhoneNumber.new(number)
  contact.phone_numbers << phone_number
  update_phone_number(contact, phone_number, options)
  @storage.save_contact(contact)
end
remove(contact, number) click to toggle source
# File lib/ppl/service/phone_number.rb, line 18
def remove(contact, number)
  contact.phone_numbers.select! do |phone_number|
    phone_number.number != number
  end
  @storage.save_contact(contact)
end
update(contact, number, options) click to toggle source
# File lib/ppl/service/phone_number.rb, line 12
def update(contact, number, options)
  matching_numbers = contact.phone_numbers.select { |p| p.number == number }
  matching_numbers.each { |mn| update_phone_number(contact, mn, options) }
  @storage.save_contact(contact)
end

Private Instance Methods

update_phone_number(contact, phone_number, options) click to toggle source
# File lib/ppl/service/phone_number.rb, line 27
def update_phone_number(contact, phone_number, options)
  if options[:type]
    phone_number.type = options[:type]
  end
  if options[:preferred] == true
    contact.phone_numbers.each { |p| p.preferred = (p.number == phone_number.number) }
  elsif options[:preferred] == false
    phone_number.preferred = false
  end
end