Class UserChoices::ChoicesBuilder
In: lib/user-choices/builder.rb
Parent: Object

This class accepts a series of source and choice descriptions and then builds a hash-like object that describes all the choices a user has made before (or while) invoking a script.


Public Class methods

Public Instance methods

Add the choice named choice, a symbol. args is a keyword argument:

  • :default takes a value that is the default value of the choice.
  • :type can be given an array of valid string values. These are checked.
  • :type can also be given :integer. The value is cast into an integer. If that‘s impossible, an exception is raised.
  • :type can also be given :boolean. The value is converted into true or false (or an exception is raised).
  • :type can also be given [:string]. The value will be an array of strings. For example, "—value a,b,c" will produce [‘a’, ‘b’, ‘c’].

You might also give :length => 5 or :length => 3..4. (In this case, a :type of [:string] is assumed.)

The block is passed a CommandLineSource object. It‘s used to describe the command line.

Add a single line composed of string to the current position in the help output.

This adds a source of choices. The source is a class like CommandLineSource. The messages_and_args are sent to a new object of that class.

Once sources and choices have been described, this builds and returns a hash-like object indexed by the choices.

Demarcate a section of help text. It begins with the description, ends with a dashed line.

In groups of related commands, there are often choices that apply to all commands and choices that apply only to this particular command. Use this to define the latter.