Class: Fuelcell::Action::OptDefinition

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Callable

#call, #callable, #callable?

Constructor Details

#initialize(text, config = {}) ⇒ OptDefinition

Returns a new instance of 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 }
  @banner   = config[:banner] || ''
  @cmd_path = config[:cmd_path]
  callable config[:run] if config.key?(:run)
end

Instance Attribute Details

Returns the value of attribute banner.



12
13
14
# File 'lib/fuelcell/action/opt_definition.rb', line 12

def banner
  @banner
end

#cli_labelsObject (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_namesObject (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_pathObject (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

#defaultObject (readonly)

Returns the value of attribute default.



12
13
14
# File 'lib/fuelcell/action/opt_definition.rb', line 12

def default
  @default
end

#flagObject (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

#globalObject (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

#longObject (readonly)

Returns the value of attribute long.



12
13
14
# File 'lib/fuelcell/action/opt_definition.rb', line 12

def long
  @long
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/fuelcell/action/opt_definition.rb', line 12

def name
  @name
end

#namesObject (readonly)

Returns the value of attribute names.



12
13
14
# File 'lib/fuelcell/action/opt_definition.rb', line 12

def names
  @names
end

#requiredObject (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

#shortObject (readonly)

Returns the value of attribute short.



12
13
14
# File 'lib/fuelcell/action/opt_definition.rb', line 12

def short
  @short
end

#typeObject (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

Returns:

  • (Boolean)


39
40
41
# File 'lib/fuelcell/action/opt_definition.rb', line 39

def cmd_path?
  !cmd_path.nil?
end

#default?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


35
36
37
# File 'lib/fuelcell/action/opt_definition.rb', line 35

def name?(value)
  names.include?(value)
end