Class: Ppl::Command::Mutt

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

Instance Attribute Summary collapse

Attributes inherited from Application::Command

#description, #name, #storage

Instance Method Summary collapse

Constructor Details

#initializeMutt

Returns a new instance of Mutt.



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

def initialize
  @name        = "mutt"
  @description = "Integration with mutt's query_command"

  @format = Ppl::Format::AddressBook::MuttQuery.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/mutt.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ppl/command/mutt.rb', line 17

def execute(input, output)
  query = input.arguments.shift
  if query.nil?
    raise Ppl::Error::IncorrectUsage, "You must provide a query"
  end

  address_book = @storage.load_address_book

  matches = mutt_search(address_book, query)

  if matches.count > 0

    line = sprintf(
      "Searching database... %d entries... %d matching:",
      address_book.count,
      matches.count
    )

    results = @format.process(matches)

    output.line(line)
    output.line(results) unless results == ""
    true

  else
    output.line("No matches")
    false
  end

end

#options(parser, options) ⇒ Object



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

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