Class: Treehouse::Options
- Inherits:
-
Object
- Object
- Treehouse::Options
- Defined in:
- lib/treehouse-dl/options.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Options
constructor
A new instance of Options.
- #parse(argv) ⇒ Object
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
#email ⇒ Object (readonly)
Returns the value of attribute email.
6 7 8 |
# File 'lib/treehouse-dl/options.rb', line 6 def email @email end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
7 8 9 |
# File 'lib/treehouse-dl/options.rb', line 7 def password @password end |
#url ⇒ Object (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. = "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., "\n", opts exit end end end |