Class: ArgumentParser
- Inherits:
-
Object
- Object
- ArgumentParser
- Defined in:
- lib/argument_parser.rb
Instance Attribute Summary collapse
-
#data_file ⇒ Object
readonly
Returns the value of attribute data_file.
-
#words_to_generate ⇒ Object
readonly
Returns the value of attribute words_to_generate.
Instance Method Summary collapse
-
#initialize ⇒ ArgumentParser
constructor
A new instance of ArgumentParser.
- #parse_arguments ⇒ Object
Constructor Details
#initialize ⇒ ArgumentParser
Returns a new instance of ArgumentParser.
6 7 8 9 10 11 12 13 |
# File 'lib/argument_parser.rb', line 6 def initialize @opts = GetoptLong.new( ["--datafile", "-d", GetoptLong::OPTIONAL_ARGUMENT], ["--number-of-words", "-n", GetoptLong::OPTIONAL_ARGUMENT] ) @data_file = "data.txt" @words_to_generate = 10 end |
Instance Attribute Details
#data_file ⇒ Object (readonly)
Returns the value of attribute data_file.
4 5 6 |
# File 'lib/argument_parser.rb', line 4 def data_file @data_file end |
#words_to_generate ⇒ Object (readonly)
Returns the value of attribute words_to_generate.
4 5 6 |
# File 'lib/argument_parser.rb', line 4 def words_to_generate @words_to_generate end |
Instance Method Details
#parse_arguments ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/argument_parser.rb', line 15 def parse_arguments @opts.each do |opt, arg| case opt when '--datafile' @data_file = arg when '--number-of-words' @words_to_generate = arg end end end |