Class: UsageMod::Option
- Inherits:
-
Object
- Object
- UsageMod::Option
- Defined in:
- lib/Usage.rb
Overview
This class represents an option (something that starts with a ‘-’ or ‘–’) and its characteristics, such as:
-
whether it is required or not
-
its short and long names
-
its type if it has one (default is string)
-
the choices for it if it is an option with fixed number of choices
-
its description
Instance Attribute Summary collapse
-
#arg_name ⇒ Object
Returns the value of attribute arg_name.
-
#arg_type ⇒ Object
Returns the value of attribute arg_type.
-
#choices ⇒ Object
Returns the value of attribute choices.
-
#description ⇒ Object
Returns the value of attribute description.
-
#has_argument ⇒ Object
Returns the value of attribute has_argument.
-
#is_required ⇒ Object
Returns the value of attribute is_required.
-
#long_name ⇒ Object
Returns the value of attribute long_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#==(other) ⇒ Object
allow it to be compared with other Option objects.
-
#hash ⇒ Object
allow it to be used in a hash.
-
#initialize(name) ⇒ Option
constructor
A new instance of Option.
-
#long_name_as_symbol ⇒ Object
the long option name as a symbol (ie. –long_name is :long_name).
-
#name_as_symbol ⇒ Object
the option name as a symbol (ie. :dash_x if -x is the option).
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ Option
Returns a new instance of Option.
207 208 209 210 211 212 213 214 215 |
# File 'lib/Usage.rb', line 207 def initialize(name) @name = name @long_name = nil @arg_name = nil @arg_type = nil @has_argument = nil @is_required = true @choices = Choices.new([]) end |
Instance Attribute Details
#arg_name ⇒ Object
Returns the value of attribute arg_name.
205 206 207 |
# File 'lib/Usage.rb', line 205 def arg_name @arg_name end |
#arg_type ⇒ Object
Returns the value of attribute arg_type.
205 206 207 |
# File 'lib/Usage.rb', line 205 def arg_type @arg_type end |
#choices ⇒ Object
Returns the value of attribute choices.
206 207 208 |
# File 'lib/Usage.rb', line 206 def choices @choices end |
#description ⇒ Object
Returns the value of attribute description.
206 207 208 |
# File 'lib/Usage.rb', line 206 def description @description end |
#has_argument ⇒ Object
Returns the value of attribute has_argument.
206 207 208 |
# File 'lib/Usage.rb', line 206 def has_argument @has_argument end |
#is_required ⇒ Object
Returns the value of attribute is_required.
205 206 207 |
# File 'lib/Usage.rb', line 205 def is_required @is_required end |
#long_name ⇒ Object
Returns the value of attribute long_name.
205 206 207 |
# File 'lib/Usage.rb', line 205 def long_name @long_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
204 205 206 |
# File 'lib/Usage.rb', line 204 def name @name end |
Instance Method Details
#==(other) ⇒ Object
allow it to be compared with other Option objects
227 228 229 |
# File 'lib/Usage.rb', line 227 def ==(other) @name = other.name end |
#hash ⇒ Object
allow it to be used in a hash
220 221 222 |
# File 'lib/Usage.rb', line 220 def hash @name.hash end |
#long_name_as_symbol ⇒ Object
the long option name as a symbol (ie. –long_name is :long_name)
241 242 243 |
# File 'lib/Usage.rb', line 241 def long_name_as_symbol @long_name.gsub(/-/, "_") end |
#name_as_symbol ⇒ Object
the option name as a symbol (ie. :dash_x if -x is the option)
234 235 236 |
# File 'lib/Usage.rb', line 234 def name_as_symbol "dash_#{@name}" end |
#to_s ⇒ Object
245 246 247 |
# File 'lib/Usage.rb', line 245 def to_s "OPTION:[#{@name}][#{@long_name}][#{@arg_type}][required=#{@is_required}]" end |