Class: CLASP::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/clasp/aliases.rb

Overview

A class that represents the specification for a command-line option

Instance Attribute Summary collapse

Instance Method Summary collapse

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 be nil.

    • values_range

      (Array) 0 or more strings specifying values supported by the option.

    • default_value

      (String) The default value of the option. May be nil.

    • extras

      An application-defined additional parameter. If nil, it is assigned an empty Hash.



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

#aliasesObject (readonly)

The option’s aliases array



148
149
150
# File 'lib/clasp/aliases.rb', line 148

def aliases
  @aliases
end

#default_valueObject (readonly)

The default value of the option



154
155
156
# File 'lib/clasp/aliases.rb', line 154

def default_value
  @default_value
end

#extrasObject (readonly)

The flag’s extras



156
157
158
# File 'lib/clasp/aliases.rb', line 156

def extras
  @extras
end

#helpObject (readonly)

The option’s help string



150
151
152
# File 'lib/clasp/aliases.rb', line 150

def help
  @help
end

#nameObject (readonly)

The option’s name string



146
147
148
# File 'lib/clasp/aliases.rb', line 146

def name
  @name
end

#values_rangeObject (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_sObject

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