Class: Ppl::Command::Add

Inherits:
Application::Command show all
Defined in:
lib/ppl/command/add.rb

Instance Attribute Summary collapse

Attributes inherited from Application::Command

#storage

Instance Method Summary collapse

Methods inherited from Application::Command

add_property

Instance Attribute Details

#name_service=(value) ⇒ Object (writeonly)

Sets the attribute name_service

Parameters:

  • value

    the value to set the attribute name_service to.



3
4
5
# File 'lib/ppl/command/add.rb', line 3

def name_service=(value)
  @name_service = value
end

Instance Method Details

#execute(input, output) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ppl/command/add.rb', line 12

def execute(input, output)
  contact_id   = input.arguments.shift
  contact_name = input.arguments.shift

  if contact_id.nil?
    raise Ppl::Error::IncorrectUsage, "No contact specified"
  end

  if contact_name.nil?
    raise Ppl::Error::IncorrectUsage, "No name specified"
  end

  contact = Ppl::Entity::Contact.new
  contact.id = contact_id.dup
  contact.name = @name_service.parse contact_name.dup

  @storage.save_contact(contact)
  return true
end

#options(parser, options) ⇒ Object



8
9
10
# File 'lib/ppl/command/add.rb', line 8

def options(parser, options)
  parser.banner = "usage: ppl add <contact> <name>"
end