Class: Ppl::Command::Show

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

Instance Attribute Summary collapse

Attributes inherited from Application::Command

#description, #name, #storage

Instance Method Summary collapse

Constructor Details

#initializeShow

Returns a new instance of Show.



6
7
8
9
10
11
# File 'lib/ppl/command/show.rb', line 6

def initialize
  @name        = "show"
  @description = "Display the full details of a contact"

  @format = Ppl::Format::Contact::Full.new
end

Instance Attribute Details

#format=(value) ⇒ Object (writeonly)

Sets the attribute format

Parameters:

  • value

    the value to set the attribute format to.



4
5
6
# File 'lib/ppl/command/show.rb', line 4

def format=(value)
  @format = value
end

Instance Method Details

#execute(input, output) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ppl/command/show.rb', line 17

def execute(input, output)
  contact_id = input.arguments.shift
  if contact_id.nil?
    raise Ppl::Error::IncorrectUsage, "No contact specified"
  end

  contact   = @storage.require_contact(contact_id)
  formatted = @format.process(contact)

  output.line(formatted)
  return true
end

#options(parser, options) ⇒ Object



13
14
15
# File 'lib/ppl/command/show.rb', line 13

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