Sha256: fbdbb5da1fd919d9b174ffe192152a60318ad92b2055f74b6c4587323a5f4334

Contents?: true

Size: 1.29 KB

Versions: 19

Compression:

Stored size: 1.29 KB

Contents

class Ppl::Command::Attribute < Ppl::Application::Command

  attr_writer :attribute
  attr_writer :list_format
  attr_writer :show_format

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


  private

  def determine_action(input)
    if input.arguments[0].nil?
      :list_attribute
    elsif input.arguments[1].nil?
      :show_attribute
    elsif input.options[:delete]
      :remove_attribute
    else
      :add_attribute
    end
  end

  def list_attribute(input, output)
    address_book = @storage.load_address_book
    if input.options[:no_color]
      @list_format.disable_colors!
    end
    output.line(@list_format.process(address_book))
    true
  end

  def show_attribute(input, output)
    contact = @storage.require_contact(input.arguments[0])
    output.line(@show_format.process(contact))
    true
  end

  def add_attribute(input, output)
    contact = @storage.require_contact(input.arguments[0])
    values = contact.send(@attribute)
    values.push(input.arguments[1].dup)
    @storage.save_contact(contact)
    true
  end

  def remove_attribute(input, output)
    contact = @storage.require_contact(input.arguments[0])
    values = contact.send(@attribute)
    values.delete(input.arguments[1])
    @storage.save_contact(contact)
  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ppl-3.0.1 lib/ppl/command/attribute.rb
ppl-3.0.0 lib/ppl/command/attribute.rb
ppl-2.4.1 lib/ppl/command/attribute.rb
ppl-2.4.0 lib/ppl/command/attribute.rb
ppl-2.3.3 lib/ppl/command/attribute.rb
ppl-2.3.2 lib/ppl/command/attribute.rb
ppl-2.3.1 lib/ppl/command/attribute.rb
ppl-2.3.0 lib/ppl/command/attribute.rb
ppl-2.2.0 lib/ppl/command/attribute.rb
ppl-2.1.0 lib/ppl/command/attribute.rb
ppl-2.0.0 lib/ppl/command/attribute.rb
ppl-1.25.0 lib/ppl/command/attribute.rb
ppl-1.24.0 lib/ppl/command/attribute.rb
ppl-1.23.0 lib/ppl/command/attribute.rb
ppl-1.22.2 lib/ppl/command/attribute.rb
ppl-1.22.1 lib/ppl/command/attribute.rb
ppl-1.22.0 lib/ppl/command/attribute.rb
ppl-1.21.0 lib/ppl/command/attribute.rb
ppl-1.20.0 lib/ppl/command/attribute.rb