class Ppl::Command::Phone
Attributes
list_format[W]
phone_service[W]
show_format[W]
Public Instance Methods
execute(input, output)
click to toggle source
# File lib/ppl/command/phone.rb, line 26 def execute(input, output) action = determine_action(input) send(action, input, output) true end
options(parser, options)
click to toggle source
# File lib/ppl/command/phone.rb, line 10 def options(parser, options) parser.banner = "usage: ppl phone <contact> [<number>]" parser.on("-d", "--delete", "delete phone number") do options[:delete] = true end parser.on("-t", "--type <type>", "set the phone number's type") do |type| options[:type] = type end parser.on("-p", "--preferred", "mark phone number as preferred") do options[:preferred] = true end parser.on("-P", "--not-preferred", "mark phone number as not preferred") do options[:preferred] = false end end
Private Instance Methods
determine_action(input)
click to toggle source
# File lib/ppl/command/phone.rb, line 34 def determine_action(input) if input.arguments.length < 1 :list_address_book_phone_numbers elsif input.arguments.length < 2 :show_contact_phone_numbers elsif input.options[:delete] :remove_phone_number_from_contact else :update_contact_phone_numbers end end
list_address_book_phone_numbers(input, output)
click to toggle source
# File lib/ppl/command/phone.rb, line 46 def list_address_book_phone_numbers(input, output) address_book = @storage.load_address_book output.line(@list_format.process(address_book)) end
new_phone_number?(contact, number)
click to toggle source
# File lib/ppl/command/phone.rb, line 70 def new_phone_number?(contact, number) (contact.phone_numbers.select { |pn| pn.number == number }).empty? end
remove_phone_number_from_contact(input, output)
click to toggle source
# File lib/ppl/command/phone.rb, line 56 def remove_phone_number_from_contact(input, output) contact = @storage.require_contact(input.arguments[0]) @phone_service.remove(contact, input.arguments[1]) end
show_contact_phone_numbers(input, output)
click to toggle source
# File lib/ppl/command/phone.rb, line 51 def show_contact_phone_numbers(input, output) contact = @storage.require_contact(input.arguments[0]) output.line(@show_format.process(contact)) end
update_contact_phone_numbers(input, output)
click to toggle source
# File lib/ppl/command/phone.rb, line 61 def update_contact_phone_numbers(input, output) contact = @storage.require_contact(input.arguments[0]) if new_phone_number?(contact, input.arguments[1]) @phone_service.add(contact, input.arguments[1], input.options) else @phone_service.update(contact, input.arguments[1], input.options) end end