Class: YoutubeCrawler::Cli
- Inherits:
-
Object
- Object
- YoutubeCrawler::Cli
- Defined in:
- lib/youtube/cli.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #execute! ⇒ Object
- #extract_options ⇒ Object
-
#initialize(argv) ⇒ Cli
constructor
A new instance of Cli.
Constructor Details
#initialize(argv) ⇒ Cli
Returns a new instance of Cli.
11 12 13 14 15 |
# File 'lib/youtube/cli.rb', line 11 def initialize(argv) @options = {} @argv = argv end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/youtube/cli.rb', line 9 def @options end |
Instance Method Details
#execute! ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/youtube/cli.rb', line 18 def execute! if !@options[:search] && !@options[:max_results] puts 'Try youtube-crawler -s <SEARCH_TERM>' puts @opts elsif ![:search] puts @opts else YoutubeCrawler::Search.new(@options).run end end |
#extract_options ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/youtube/cli.rb', line 29 def @opts= OptionParser.new @opts. = "Usage: commander [options] ..." @options[:verbose] = false @opts.on( '-v', '--verbose', 'Output more information' ) do @options[:verbose] = true end @options[:search] = false @opts.on( '-s', '--search ', Array, 'Search term. For multiple words use: Term1,Term2,Term3 etc.' ) do |opt| # works .. but sucks @options[:search] = opt end @options[:max_results] = false @opts.on( '-m', '--max_results max_results', 'Max results displayed (default is 5)' ) do |opt| @options[:max_results] = opt end @options[:player] = false @opts.on( '-p', '--player player', 'Choose media player(default is vlc)' ) do |opt| @options[:player] = opt end @opts.on( '-h', '--help', 'Display this screen' ) do puts @opts exit end @opts.on( '', '--version', 'Print programm version' ) do puts YoutubeCrawler::VERSION exit end @opts.parse(@argv) end |