Class: Dicey::CLI::Options Private
- Inherits:
-
Object
- Object
- Dicey::CLI::Options
- Defined in:
- lib/dicey/cli/options.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Helper class for parsing command-line options and generating help.
Constant Summary collapse
- MODES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Allowed modes (–mode) (only directly selectable).
%w[distribution roll].freeze
- RESULT_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Allowed result types (–result).
%w[weights probabilities].freeze
- FORMATS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Allowed output formats (–format).
%w[list gnuplot json yaml null].freeze
- DEFAULT_OPTIONS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default values for initial values of the options.
{ mode: "distribution", format: "list", result: "weights" }.freeze
Instance Method Summary collapse
-
#[](key) ⇒ Object
private
Get an option value by key.
-
#initialize(initial_options = DEFAULT_OPTIONS.dup) ⇒ Options
constructor
private
A new instance of Options.
-
#read(argv) ⇒ Array<String>
private
Parse command-line arguments as options and return non-option arguments.
- #to_h ⇒ Hash{Symbol => Object} private
Constructor Details
#initialize(initial_options = DEFAULT_OPTIONS.dup) ⇒ Options
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Options.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dicey/cli/options.rb', line 19 def initialize( = DEFAULT_OPTIONS.dup) @options = @parser = ::OptionParser.new @parser.program_name = "Dicey" @parser.version = Dicey::VERSION end |
Instance Method Details
#[](key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get an option value by key.
43 44 45 |
# File 'lib/dicey/cli/options.rb', line 43 def [](key) @options[key] end |
#read(argv) ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parse command-line arguments as options and return non-option arguments.
35 36 37 |
# File 'lib/dicey/cli/options.rb', line 35 def read(argv) @parser.parse!(argv, into: @options) end |
#to_h ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 |
# File 'lib/dicey/cli/options.rb', line 48 def to_h @options.dup end |