Sha256: 22bf53f650fcd2727018175226a559cb795b575f8f35e73305b3c58ee5e4eadd

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

class Ppl::Command::Phone < Ppl::Application::Command

  name        "phone"
  description "List, show or change phone numbers"

  attr_writer :show_format
  attr_writer :list_format

  def initialize
    @show_format = Ppl::Format::Contact::PhoneNumber.new
    @list_format = Ppl::Format::AddressBook::PhoneNumbers.new
  end

  def options(parser, options)
    parser.banner = "usage: ppl phone <contact> [<number>]"
  end

  def execute(input, output)
    action = determine_action(input)
    send(action, input, output)
  end


  private

  def determine_action(input)
    if input.arguments[0].nil?
      :list_phone_numbers
    elsif input.arguments[1].nil?
      :show_phone_number
    else
      :set_phone_number
    end
  end

  def list_phone_numbers(input, output)
    address_book = @storage.load_address_book
    number_list  = @list_format.process(address_book)
    output.line(number_list)
  end

  def show_phone_number(input, output)
    contact = @storage.require_contact(input.arguments[0])
    number  = @show_format.process(contact)
    if number != ""
      output.line(number)
      true
    else
      false
    end
  end

  def set_phone_number(input, output)
    contact = @storage.require_contact(input.arguments[0])
    contact.phone_number = input.arguments[1]
    @storage.save_contact(contact)
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ppl-1.9.0 lib/ppl/command/phone.rb
ppl-1.8.0 lib/ppl/command/phone.rb
ppl-1.7.0 lib/ppl/command/phone.rb
ppl-1.6.0 lib/ppl/command/phone.rb
ppl-1.5.3 lib/ppl/command/phone.rb