Class: ArgumentParser

Inherits:
Object
  • Object
show all
Defined in:
lib/argument_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeArgumentParser

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_fileObject (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_generateObject (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_argumentsObject



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