Class: BoggleSolver::Options
- Inherits:
-
Object
- Object
- BoggleSolver::Options
- Defined in:
- lib/boggle_solver/options.rb
Constant Summary collapse
- DEFAULT_DICTIONARY =
"/usr/share/dict/words"
Instance Attribute Summary collapse
-
#dictionary ⇒ Object
readonly
Returns the value of attribute dictionary.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Options
constructor
A new instance of Options.
- #parse(argv) ⇒ Object
Constructor Details
#initialize(argv) ⇒ Options
10 11 12 13 14 15 16 |
# File 'lib/boggle_solver/options.rb', line 10 def initialize(argv) @dictionary = DEFAULT_DICTIONARY @mode = :default parse(argv) @input = argv[0] @mode = :given unless argv.empty? end |
Instance Attribute Details
#dictionary ⇒ Object (readonly)
Returns the value of attribute dictionary.
8 9 10 |
# File 'lib/boggle_solver/options.rb', line 8 def dictionary @dictionary end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
8 9 10 |
# File 'lib/boggle_solver/options.rb', line 8 def input @input end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
8 9 10 |
# File 'lib/boggle_solver/options.rb', line 8 def mode @mode end |
Instance Method Details
#parse(argv) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/boggle_solver/options.rb', line 18 def parse(argv) OptionParser.new do |opts| opts. = "Usage: boggle_solver [ options ] " opts.on("-d", "--dict path", String, "Path to dictionary") do |dict| @dictionary = dict end opts.on("-h", "--help", "Show this message") do puts opts exit end opts.on("-r", "--random", "Use a random board") do @mode = :random end begin argv = ["-r"] if argv.empty? opts.parse!(argv) rescue OptionParser::ParseError => e STDERR.puts e., "\n", opts exit(-1) end end end |