Class: Ppl::Command::Mutt
- Inherits:
-
Application::Command
- Object
- Application::Command
- Ppl::Command::Mutt
- Defined in:
- lib/ppl/command/mutt.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
writeonly
Sets the attribute format.
Attributes inherited from Application::Command
Instance Method Summary collapse
- #execute(input, output) ⇒ Object
-
#initialize ⇒ Mutt
constructor
A new instance of Mutt.
- #options(parser, options) ⇒ Object
Constructor Details
Instance Attribute Details
#format=(value) ⇒ Object (writeonly)
Sets the attribute format
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 (parser, ) parser. = "usage: ppl mutt <query>" end |