Class: Consoler::Option
- Inherits:
-
Object
- Object
- Consoler::Option
- Defined in:
- lib/consoler/option.rb
Overview
Represents an option
Instance Attribute Summary collapse
-
#is_argument ⇒ Boolean
readonly
Is the option an argument.
-
#is_long ⇒ Boolean
readonly
Is the option long (
--option
). -
#is_optional ⇒ Integer
readonly
Is the option optional (> 0) (
[option]
). -
#is_short ⇒ Boolean
readonly
Is the option short (
-o
). -
#is_value ⇒ Boolean
readonly
Does the option need a value (
--option=
). -
#name ⇒ String
readonly
Name of the options.
Class Method Summary collapse
-
.create(option_def, tracker) ⇒ Object
Create a option.
Instance Method Summary collapse
-
#default_value ⇒ nil | 0 | false
Get the default value of this option.
-
#to_definition ⇒ String
Get the definition of the option.
Instance Attribute Details
#is_argument ⇒ Boolean (readonly)
Is the option an argument
13 14 15 |
# File 'lib/consoler/option.rb', line 13 def is_argument @is_argument end |
#is_long ⇒ Boolean (readonly)
Is the option long (--option
)
13 14 15 |
# File 'lib/consoler/option.rb', line 13 def is_long @is_long end |
#is_optional ⇒ Integer (readonly)
Is the option optional (> 0) ([option]
)
13 14 15 |
# File 'lib/consoler/option.rb', line 13 def is_optional @is_optional end |
#is_short ⇒ Boolean (readonly)
Is the option short (-o
)
13 14 15 |
# File 'lib/consoler/option.rb', line 13 def is_short @is_short end |
#is_value ⇒ Boolean (readonly)
Does the option need a value (--option=
)
13 14 15 |
# File 'lib/consoler/option.rb', line 13 def is_value @is_value end |
#name ⇒ String (readonly)
Name of the options
13 14 15 |
# File 'lib/consoler/option.rb', line 13 def name @name end |
Class Method Details
.create(option_def, tracker) ⇒ Object
Create a option
Yields an option for every option detected
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/consoler/option.rb', line 27 def self.create(option_def, tracker) option = Option.new option_def, tracker if option.is_short and option.name.size > 1 then old_tracking = tracker.is_tracking old_is_value = option.is_value if option.is_optional then tracker.is_tracking = true end names = option.name.split('') names.each_with_index do |name, i| new_name = "-#{name}" if old_is_value and i == names.count - 1 then new_name = "#{new_name}=" end yield Option.new new_name, tracker end tracker.is_tracking = old_tracking else yield option end end |
Instance Method Details
#default_value ⇒ nil | 0 | false
Get the default value of this option
81 82 83 84 85 86 87 |
# File 'lib/consoler/option.rb', line 81 def default_value return nil if is_value return 0 if is_short return false if is_long return nil end |
#to_definition ⇒ String
Get the definition of the option
Does not include the optional information, as that is linked to other options
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/consoler/option.rb', line 62 def to_definition definition = name if is_long then definition = "--#{definition}" elsif is_short then definition = "-#{definition}" end if is_value then definition = "#{definition}=" end definition end |