Class: Tweetwine::CLI::SearchCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/tweetwine/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

abort_with_usage, about, inherited, #initialize, name, register, show_usage, usage

Constructor Details

This class inherits a constructor from Tweetwine::CLI::Command

Class Method Details

.parserObject



300
301
302
303
304
305
306
307
308
309
# File 'lib/tweetwine/cli.rb', line 300

def self.parser
  @parser ||= OptionParser.new do |parser, options|
    parser.on '-a', '--and',  'All words match (default).' do
      options[:operator] = :and
    end
    parser.on '-o', '--or',   'Any word matches.' do
      options[:operator] = :or
    end
  end
end

Instance Method Details

#parse(args) ⇒ Object



322
323
324
325
326
327
328
329
330
331
332
# File 'lib/tweetwine/cli.rb', line 322

def parse(args)
  options = self.class.parser.parse(args)
  @operator = options[:operator]
  @words = args
  if @words.empty?
    CLI.ui.error "No search words.\n\n"
    false
  else
    true
  end
end

#runObject



334
335
336
# File 'lib/tweetwine/cli.rb', line 334

def run
  CLI.twitter.search @words, @operator
end