Sha256: bbc94a90bcf34f4847311e744336c4d5c7eba7d14f65ffa4ca48f7e7eaa7ebf8

Contents?: true

Size: 1.75 KB

Versions: 10

Compression:

Stored size: 1.75 KB

Contents

class Ppl::Command::Name < Ppl::Application::Command

  name        "name"
  description "List, show or change names"

  attr_writer :show_format
  attr_writer :list_format
  attr_writer :name_service

  def options(parser, options)
    parser.banner = "usage: ppl name <contact> [<name>]"
    parser.on("-f", "--family <family-name(s)>") do |family|
      options[:family] = family
    end
    parser.on("-g", "--given <given-name(s)>") do |given|
      options[:given] = given
    end
    parser.on("-m", "--middle <middle-name(s)>") do |middle|
      options[:middle] = middle
    end
    parser.on("-p", "--prefix <prefix>") do |prefix|
      options[:prefix] = prefix
    end
    parser.on("-s", "--suffix <suffix>") do |suffix|
      options[:suffix] = suffix
    end
  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_names
    elsif input.arguments[1].nil? && input.options.empty?
      :show_name
    else
      :set_name
    end
  end

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

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

  def set_name(input, output)
    contact = @storage.require_contact(input.arguments[0])
    options = input.options.dup
    if !input.arguments[1].nil?
      options[:full] = input.arguments[1].dup
    end
    @name_service.update(contact.name, options)
    @storage.save_contact(contact)
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ppl-3.0.1 lib/ppl/command/name.rb
ppl-3.0.0 lib/ppl/command/name.rb
ppl-2.4.1 lib/ppl/command/name.rb
ppl-2.4.0 lib/ppl/command/name.rb
ppl-2.3.3 lib/ppl/command/name.rb
ppl-2.3.2 lib/ppl/command/name.rb
ppl-2.3.1 lib/ppl/command/name.rb
ppl-2.3.0 lib/ppl/command/name.rb
ppl-2.2.0 lib/ppl/command/name.rb
ppl-2.1.0 lib/ppl/command/name.rb