Class: IDL::OptionList::Option
- Inherits:
-
Object
- Object
- IDL::OptionList::Option
- Defined in:
- lib/ridl/optparse_ext.rb
Defined Under Namespace
Classes: Configurator, Group
Instance Attribute Summary collapse
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
-
#switch ⇒ Object
readonly
Returns the value of attribute switch.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #description(indent = "") ⇒ Object
-
#initialize(switch, options) ⇒ Option
constructor
A new instance of Option.
- #run(arg, options) ⇒ Object
Constructor Details
#initialize(switch, options) ⇒ Option
Returns a new instance of Option.
307 308 309 310 311 312 313 |
# File 'lib/ridl/optparse_ext.rb', line 307 def initialize(switch, ) @switch = switch @type = [:type] || TrueClass @separator = [:separator] == true @description = Array === [:description] ? [:description] : ([:description] ? [:description].split('\n') : ['']) @groups = {} end |
Instance Attribute Details
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
306 307 308 |
# File 'lib/ridl/optparse_ext.rb', line 306 def groups @groups end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
305 306 307 |
# File 'lib/ridl/optparse_ext.rb', line 305 def separator @separator end |
#switch ⇒ Object (readonly)
Returns the value of attribute switch.
303 304 305 |
# File 'lib/ridl/optparse_ext.rb', line 303 def switch @switch end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
304 305 306 |
# File 'lib/ridl/optparse_ext.rb', line 304 def type @type end |
Instance Method Details
#description(indent = "") ⇒ Object
315 316 317 |
# File 'lib/ridl/optparse_ext.rb', line 315 def description(indent = "") @groups.values.inject(@description.dup) {|desc, h| desc.concat(h.description.collect {|desc| "\r#{indent} #{desc}"}) } end |
#run(arg, options) ⇒ Object
319 320 321 322 323 |
# File 'lib/ridl/optparse_ext.rb', line 319 def run(arg, ) unless @groups.values.inject(false) {|f, h| h.run(arg, ) || f } raise ArgumentError, "unknown option [#{arg}] for switch '#{@switch}'" end end |