Class: Treehouse::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/treehouse-dl/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Options

Returns a new instance of Options.



10
11
12
# File 'lib/treehouse-dl/options.rb', line 10

def initialize(argv)
  parse(argv)
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



6
7
8
# File 'lib/treehouse-dl/options.rb', line 6

def email
  @email
end

#passwordObject (readonly)

Returns the value of attribute password.



7
8
9
# File 'lib/treehouse-dl/options.rb', line 7

def password
  @password
end

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/treehouse-dl/options.rb', line 8

def url
  @url
end

Instance Method Details

#parse(argv) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/treehouse-dl/options.rb', line 13

def parse(argv)
  OptionParser.new do |opts|
    opts.banner = "Usage: treehouse-dl [options] -e EMAIL -p PASSWORD -u URL"
    opts.on('-e','--email EMAIL','Set email') do |email|
      @email = email
    end
    opts.on('-p','--password PASSWORD','Set password') do |password|
      @password = password
    end
    opts.on('-u','--url URL','Course URL')      do |url|
      @url = url
    end
    opts.on("-h", "--help", "Show all options") do
      puts opts
      exit
    end
    begin
      argv = ['-h'] if argv.empty?
      opts.parse!(argv)
    rescue OptionParser::ParseError => e
      STDERR.puts e.message, "\n", opts
      exit
    end
  end
end