Sha256: f50e589cfe46d521cb8e0747ed5b93540b83799260ab721d11ce7f2fa014a84f

Contents?: true

Size: 1.32 KB

Versions: 13

Compression:

Stored size: 1.32 KB

Contents

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

  attr_writer :show_format
  attr_writer :list_format

  def initialize
    @name        = "phone"
    @description = "List, show or change phone numbers"
    @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

13 entries across 13 versions & 1 rubygems

Version Path
ppl-1.5.2 lib/ppl/command/phone.rb
ppl-1.5.1 lib/ppl/command/phone.rb
ppl-1.5.0 lib/ppl/command/phone.rb
ppl-1.4.1 lib/ppl/command/phone.rb
ppl-1.3.0 lib/ppl/command/phone.rb
ppl-1.2.0 lib/ppl/command/phone.rb
ppl-1.1.0 lib/ppl/command/phone.rb
ppl-1.0.6 lib/ppl/command/phone.rb
ppl-1.0.5 lib/ppl/command/phone.rb
ppl-1.0.4 lib/ppl/command/phone.rb
ppl-1.0.3 lib/ppl/command/phone.rb
ppl-1.0.1 lib/ppl/command/phone.rb
ppl-1.0.0 lib/ppl/command/phone.rb