Class: Fuelcell::Action::OptDefinition
- Inherits:
-
Object
- Object
- Fuelcell::Action::OptDefinition
- Includes:
- Callable
- Defined in:
- lib/fuelcell/action/opt_definition.rb
Overview
Responsible for defining all the information about an option so that the parser will be able to find it and its values when processing the command line.
Constant Summary collapse
- NO_DEFAULT_ASSIGNED =
'__fuelcell_no_default_assigned__'
Instance Attribute Summary collapse
-
#banner ⇒ Object
readonly
Returns the value of attribute banner.
-
#cli_labels ⇒ Object
readonly
Returns the value of attribute cli_labels.
-
#cli_names ⇒ Object
readonly
Returns the value of attribute cli_names.
-
#cmd_path ⇒ Object
readonly
Returns the value of attribute cmd_path.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#flag ⇒ Object
(also: #flag?)
readonly
Returns the value of attribute flag.
-
#global ⇒ Object
(also: #global?)
readonly
Returns the value of attribute global.
-
#long ⇒ Object
readonly
Returns the value of attribute long.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#required ⇒ Object
(also: #required?)
readonly
Returns the value of attribute required.
-
#short ⇒ Object
readonly
Returns the value of attribute short.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #cmd_path? ⇒ Boolean
- #default? ⇒ Boolean
-
#initialize(text, config = {}) ⇒ OptDefinition
constructor
A new instance of OptDefinition.
- #name?(value) ⇒ Boolean
Methods included from Callable
Constructor Details
#initialize(text, config = {}) ⇒ OptDefinition
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fuelcell/action/opt_definition.rb', line 19 def initialize(text, config = {}) initialize_names(text) @flag = config[:flag] == true ? true : false @required = config[:required] == true ? true : false @global = config[:global] == true ? true : false @type = validate_type(config[:type]) @default = config.fetch(:default) { NO_DEFAULT_ASSIGNED } = config[:banner] || '' @cmd_path = config[:cmd_path] callable config[:run] if config.key?(:run) end |
Instance Attribute Details
#banner ⇒ Object (readonly)
Returns the value of attribute banner.
12 13 14 |
# File 'lib/fuelcell/action/opt_definition.rb', line 12 def end |
#cli_labels ⇒ Object (readonly)
Returns the value of attribute cli_labels.
12 13 14 |
# File 'lib/fuelcell/action/opt_definition.rb', line 12 def cli_labels @cli_labels end |
#cli_names ⇒ Object (readonly)
Returns the value of attribute cli_names.
12 13 14 |
# File 'lib/fuelcell/action/opt_definition.rb', line 12 def cli_names @cli_names end |
#cmd_path ⇒ Object (readonly)
Returns the value of attribute cmd_path.
12 13 14 |
# File 'lib/fuelcell/action/opt_definition.rb', line 12 def cmd_path @cmd_path end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
12 13 14 |
# File 'lib/fuelcell/action/opt_definition.rb', line 12 def default @default end |
#flag ⇒ Object (readonly) Also known as: flag?
Returns the value of attribute flag.
12 13 14 |
# File 'lib/fuelcell/action/opt_definition.rb', line 12 def flag @flag end |
#global ⇒ Object (readonly) Also known as: global?
Returns the value of attribute global.
12 13 14 |
# File 'lib/fuelcell/action/opt_definition.rb', line 12 def global @global end |
#long ⇒ Object (readonly)
Returns the value of attribute long.
12 13 14 |
# File 'lib/fuelcell/action/opt_definition.rb', line 12 def long @long end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/fuelcell/action/opt_definition.rb', line 12 def name @name end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
12 13 14 |
# File 'lib/fuelcell/action/opt_definition.rb', line 12 def names @names end |
#required ⇒ Object (readonly) Also known as: required?
Returns the value of attribute required.
12 13 14 |
# File 'lib/fuelcell/action/opt_definition.rb', line 12 def required @required end |
#short ⇒ Object (readonly)
Returns the value of attribute short.
12 13 14 |
# File 'lib/fuelcell/action/opt_definition.rb', line 12 def short @short end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
12 13 14 |
# File 'lib/fuelcell/action/opt_definition.rb', line 12 def type @type end |
Instance Method Details
#cmd_path? ⇒ Boolean
39 40 41 |
# File 'lib/fuelcell/action/opt_definition.rb', line 39 def cmd_path? !cmd_path.nil? end |
#default? ⇒ Boolean
31 32 33 |
# File 'lib/fuelcell/action/opt_definition.rb', line 31 def default? @default == NO_DEFAULT_ASSIGNED ? false : true end |
#name?(value) ⇒ Boolean
35 36 37 |
# File 'lib/fuelcell/action/opt_definition.rb', line 35 def name?(value) names.include?(value) end |