Class: CLASP::Option
- Inherits:
-
Object
- Object
- CLASP::Option
- Defined in:
- lib/clasp/aliases.rb
Overview
A class that represents the specification for a command-line option
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
The option’s aliases array.
-
#default_value ⇒ Object
readonly
The default value of the option.
-
#extras ⇒ Object
readonly
The flag’s extras.
-
#help ⇒ Object
readonly
The option’s help string.
-
#name ⇒ Object
readonly
The option’s name string.
-
#values_range ⇒ Object
readonly
The range of values supported by the option.
Instance Method Summary collapse
-
#initialize(name, aliases, help, values_range, default_value, extras = nil) ⇒ Option
constructor
Creates an Option instance from the given name, aliases, help, values_range, and default_value.
-
#to_s ⇒ Object
String form of the option.
Constructor Details
#initialize(name, aliases, help, values_range, default_value, extras = nil) ⇒ Option
Creates an Option instance from the given name, aliases, help, values_range, and default_value
Signature
-
Parameters
name
-
(
String
) The name, or long-form, of the option.
aliases
-
(
Array
) 0 or more strings specifying short-form or option-value aliases.
help
-
(
String
) The help string, which may benil
.
values_range
-
(
Array
) 0 or more strings specifying values supported by the option.
default_value
-
(
String
) The default value of the option. May benil
.
extras
-
An application-defined additional parameter. If
nil
, it is assigned an emptyHash
.
135 136 137 138 139 140 141 142 143 |
# File 'lib/clasp/aliases.rb', line 135 def initialize(name, aliases, help, values_range, default_value, extras = nil) @name = name @aliases = (aliases || []).select { |a| a and not a.empty? } @help = help @values_range = values_range || [] @default_value = default_value @extras = extras || {} end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
The option’s aliases array
148 149 150 |
# File 'lib/clasp/aliases.rb', line 148 def aliases @aliases end |
#default_value ⇒ Object (readonly)
The default value of the option
154 155 156 |
# File 'lib/clasp/aliases.rb', line 154 def default_value @default_value end |
#extras ⇒ Object (readonly)
The flag’s extras
156 157 158 |
# File 'lib/clasp/aliases.rb', line 156 def extras @extras end |
#help ⇒ Object (readonly)
The option’s help string
150 151 152 |
# File 'lib/clasp/aliases.rb', line 150 def help @help end |
#name ⇒ Object (readonly)
The option’s name string
146 147 148 |
# File 'lib/clasp/aliases.rb', line 146 def name @name end |
#values_range ⇒ Object (readonly)
The range of values supported by the option
152 153 154 |
# File 'lib/clasp/aliases.rb', line 152 def values_range @values_range end |
Instance Method Details
#to_s ⇒ Object
String form of the option
159 160 161 162 |
# File 'lib/clasp/aliases.rb', line 159 def to_s "{#{name}; aliases=#{aliases.join(', ')}; values_range=[ #{values_range.join(', ')} ]; default_value='#{default_value}'; help='#{help}'; extras=#{extras}}" end |