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

#storage

Instance Method Summary collapse

Methods inherited from Application::Command

add_property

Constructor Details

#initializeShow

Returns a new instance of Show.



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

def initialize
  @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.



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

def format=(value)
  @format = value
end

Instance Method Details

#execute(input, output) ⇒ Object



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

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



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

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