Class: Ame::Option
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
-
#argument_name ⇒ Object
readonly
Returns the value of attribute argument_name.
Attributes inherited from Argument
Instance Method Summary collapse
- #ignored? ⇒ Boolean
-
#initialize(name, description, options = {}, &validate) ⇒ Option
constructor
A new instance of Option.
- #long ⇒ Object
- #short ⇒ Object
- #to_s ⇒ Object
Methods inherited from Argument
#arity, #optional?, #process, #required?
Constructor Details
#initialize(name, description, options = {}, &validate) ⇒ Option
Returns a new instance of Option.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ame/option.rb', line 4 def initialize(name, description, = {}, &validate) is_boolean_type = [TrueClass, FalseClass].include? [:type] [:default] = false unless .include? :default or .include? :type if is_boolean_type and not .include? :default [:default] = [:type] == FalseClass end is_boolean = [true, false].include? [:default] raise ArgumentError, 'optional arguments to options are only allowed for booleans' if [:optional] and not(is_boolean_type or is_boolean) [:optional] = is_boolean raise ArgumentError, 'boolean options cannot have argument descriptions' if is_boolean and [:argument] @argument_name = is_boolean ? "" : ([:argument] || name).to_s @aliases = Array([:alias]) + Array([:aliases]) @ignored = [:ignore] super end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
28 29 30 |
# File 'lib/ame/option.rb', line 28 def aliases @aliases end |
#argument_name ⇒ Object (readonly)
Returns the value of attribute argument_name.
28 29 30 |
# File 'lib/ame/option.rb', line 28 def argument_name @argument_name end |
Instance Method Details
#ignored? ⇒ Boolean
38 39 40 |
# File 'lib/ame/option.rb', line 38 def ignored? @ignored end |
#long ⇒ Object
34 35 36 |
# File 'lib/ame/option.rb', line 34 def long [name, *aliases].find{ |a| a.to_s.length > 1 } end |
#short ⇒ Object
30 31 32 |
# File 'lib/ame/option.rb', line 30 def short [name, *aliases].find{ |a| a.to_s.length == 1 } end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/ame/option.rb', line 24 def to_s (name.to_s.length > 1 ? '--%s' : '-%s') % name end |