Class: Dicey::CLI::Options Private

Inherits:
Object
  • Object
show all
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

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(initial_options = DEFAULT_OPTIONS.dup)
  @options = initial_options
  @parser = ::OptionParser.new
  @parser.program_name = "Dicey"
  @parser.version = Dicey::VERSION

  add_banner_and_version
  add_common_options
  add_test_options
  add_other_options
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.

Parameters:

  • key (Symbol)

Returns:

  • (Object)


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.

Parameters:

  • argv (Array<String>)

Returns:

  • (Array<String>)

    non-option arguments



35
36
37
# File 'lib/dicey/cli/options.rb', line 35

def read(argv)
  @parser.parse!(argv, into: @options)
end

#to_hHash{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.

Returns:

  • (Hash{Symbol => Object})


48
49
50
# File 'lib/dicey/cli/options.rb', line 48

def to_h
  @options.dup
end