Class: CLASP::OptionSpecification
- Inherits:
-
Object
- Object
- CLASP::OptionSpecification
- Defined in:
- lib/clasp/specifications.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 option’s extras.
-
#help ⇒ Object
readonly
The option’s help string.
-
#name ⇒ Object
readonly
The option’s name string.
-
#required_message ⇒ Object
readonly
The message to be used when reporting that a required option is missing.
-
#values_range ⇒ Object
readonly
The range of values supported by the option.
Instance Method Summary collapse
-
#==(rhs) ⇒ Object
Compares instance against another OptionSpecification or against a name (String).
-
#eql?(rhs) ⇒ Boolean
:nodoc:.
-
#initialize(name, aliases, help, values_range, default_value, required, required_message, extras = nil) ⇒ OptionSpecification
constructor
Creates an OptionSpecification instance from the given name, aliases, help, values_range, and default_value.
-
#required? ⇒ Boolean
Indicates whether the option is required.
-
#to_s ⇒ Object
String form of the option.
Constructor Details
#initialize(name, aliases, help, values_range, default_value, required, required_message, extras = nil) ⇒ OptionSpecification
Creates an OptionSpecification 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
required- boolean
-
Whether the option is required. May be
nilrequired_message- ::String
-
Message to be used when reporting
that a required option is missing. May be
nilin which case a message of the form “<option-name> not specified; use –help for usage”. If begins with the nul character (“0”), then is used in the place of the <option-name> and placed into the rest of the standard form messageextras-
An application-defined additional parameter. If
nil, it is assigned an emptyHash
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/clasp/specifications.rb', line 178 def initialize(name, aliases, help, values_range, default_value, required, , extras = nil) @name = name @aliases = (aliases || []).select { |a| a and not a.empty? } @help = help @values_range = values_range || [] @default_value = default_value @required = required @required_message = nil @extras = extras || {} rm_name = nil if if "\0" == [0] rm_name = [1..-1] end else rm_name = "'#{name}'" end if rm_name = "#{rm_name} not specified; use --help for usage" end @required_message = end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
The option’s aliases array
213 214 215 |
# File 'lib/clasp/specifications.rb', line 213 def aliases @aliases end |
#default_value ⇒ Object (readonly)
The default value of the option
219 220 221 |
# File 'lib/clasp/specifications.rb', line 219 def default_value @default_value end |
#extras ⇒ Object (readonly)
The option’s extras
226 227 228 |
# File 'lib/clasp/specifications.rb', line 226 def extras @extras end |
#help ⇒ Object (readonly)
The option’s help string
215 216 217 |
# File 'lib/clasp/specifications.rb', line 215 def help @help end |
#name ⇒ Object (readonly)
The option’s name string
211 212 213 |
# File 'lib/clasp/specifications.rb', line 211 def name @name end |
#required_message ⇒ Object (readonly)
The message to be used when reporting that a required option is missing
224 225 226 |
# File 'lib/clasp/specifications.rb', line 224 def @required_message end |
#values_range ⇒ Object (readonly)
The range of values supported by the option
217 218 219 |
# File 'lib/clasp/specifications.rb', line 217 def values_range @values_range end |
Instance Method Details
#==(rhs) ⇒ Object
Compares instance against another OptionSpecification or against a name (String)
258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/clasp/specifications.rb', line 258 def == rhs case rhs when self.class return self.eql? rhs when String return name == rhs else false end end |
#eql?(rhs) ⇒ Boolean
:nodoc:
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/clasp/specifications.rb', line 234 def eql? rhs # :nodoc: case rhs when self.class ; else return false end return false unless name == rhs.name return false unless aliases == rhs.aliases return false unless help == rhs.help return false unless values_range == rhs.values_range return false unless default_value == rhs.default_value return false unless required == rhs.required return false unless == rhs. return false unless extras == rhs.extras return true end |
#required? ⇒ Boolean
Indicates whether the option is required
221 |
# File 'lib/clasp/specifications.rb', line 221 def required?; @required; end |
#to_s ⇒ Object
String form of the option
229 230 231 232 |
# File 'lib/clasp/specifications.rb', line 229 def to_s "{#{name}; aliases=#{aliases.join(', ')}; values_range=[ #{values_range.join(', ')} ]; default_value='#{default_value}'; help='#{help}'; required?=#{required?}; extras=#{extras}}" end |