Class: Ppl::Service::PhoneNumber

Inherits:
Object
  • Object
show all
Defined in:
lib/ppl/service/phone_number.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#storage=(value) ⇒ Object (writeonly)

Sets the attribute storage

Parameters:

  • value

    the value to set the attribute storage to.



3
4
5
# File 'lib/ppl/service/phone_number.rb', line 3

def storage=(value)
  @storage = value
end

Instance Method Details

#add(contact, number, options) ⇒ Object



5
6
7
8
9
10
# 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) ⇒ Object



18
19
20
21
22
23
# 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) ⇒ Object



12
13
14
15
16
# 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