Class: DManga::Options
- Inherits:
-
Object
- Object
- DManga::Options
- Defined in:
- lib/dmanga/options.rb
Constant Summary collapse
- DEFAULT_DOWNLOAD_DIR =
"#{ENV['HOME']}/Downloads"
Instance Attribute Summary collapse
-
#download_dir ⇒ Object
readonly
Returns the value of attribute download_dir.
-
#manga ⇒ Object
readonly
Returns the value of attribute manga.
-
#site ⇒ Object
Returns the value of attribute site.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Options
constructor
A new instance of Options.
- #parse(argv) ⇒ Object
Constructor Details
#initialize(argv) ⇒ Options
8 9 10 11 12 13 14 |
# File 'lib/dmanga/options.rb', line 8 def initialize(argv) @download_dir = DEFAULT_DOWNLOAD_DIR @verbose = false @site = "mangahost.cc" parse(argv) @manga = argv[0] end |
Instance Attribute Details
#download_dir ⇒ Object (readonly)
Returns the value of attribute download_dir.
6 7 8 |
# File 'lib/dmanga/options.rb', line 6 def download_dir @download_dir end |
#manga ⇒ Object (readonly)
Returns the value of attribute manga.
6 7 8 |
# File 'lib/dmanga/options.rb', line 6 def manga @manga end |
#site ⇒ Object
Returns the value of attribute site.
7 8 9 |
# File 'lib/dmanga/options.rb', line 7 def site @site end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
6 7 8 |
# File 'lib/dmanga/options.rb', line 6 def verbose @verbose end |
Instance Method Details
#parse(argv) ⇒ Object
16 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 |
# File 'lib/dmanga/options.rb', line 16 def parse(argv) OptionParser.new do |opts| opts. = "Uso: dmanga [opção] <nome do manga>" opts.separator "" opts.separator "Opções:" opts.on('--version', 'Exibe o numero de versão do programa.') do puts "version #{DManga::VERSION}" exit end opts.on('-v', '--verbose', 'Exibe informações da execução do programa.') do @verbose = true end opts.on('-d', '--directory DIRETORIO', 'O diretorio de destino do download. Padrão é Downloads.') do |path| @download_dir = path end opts.on('-h', '--help', 'Exibe esta tela.') do puts opts exit end argv = ['-h'] if argv.empty? opts.parse!(argv) end end |