Sha256: a3614ff01b7c21d123eacc7769c2020239dcea31e25fe6f5b0a933f158a88b9c

Contents?: true

Size: 1.03 KB

Versions: 13

Compression:

Stored size: 1.03 KB

Contents

class Ppl::Service::PhoneNumber

  attr_writer :storage

  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

  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

  def remove(contact, number)
    contact.phone_numbers.select! do |phone_number|
      phone_number.number != number
    end
    @storage.save_contact(contact)
  end

  private

  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

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ppl-3.0.1 lib/ppl/service/phone_number.rb
ppl-3.0.0 lib/ppl/service/phone_number.rb
ppl-2.4.1 lib/ppl/service/phone_number.rb
ppl-2.4.0 lib/ppl/service/phone_number.rb
ppl-2.3.3 lib/ppl/service/phone_number.rb
ppl-2.3.2 lib/ppl/service/phone_number.rb
ppl-2.3.1 lib/ppl/service/phone_number.rb
ppl-2.3.0 lib/ppl/service/phone_number.rb
ppl-2.2.0 lib/ppl/service/phone_number.rb
ppl-2.1.0 lib/ppl/service/phone_number.rb
ppl-2.0.0 lib/ppl/service/phone_number.rb
ppl-1.25.0 lib/ppl/service/phone_number.rb
ppl-1.24.0 lib/ppl/service/phone_number.rb