Class: IDL::OptionList::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/ridl/optparse_ext.rb

Defined Under Namespace

Classes: Configurator, Group

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options)
  @switch = switch
  @type = options[:type] || TrueClass
  @separator = options[:separator] == true
  @description = Array === options[:description] ? options[:description] : (options[:description] ? options[:description].split('\n') : [''])
  @groups = {}
end

Instance Attribute Details

#groupsObject (readonly)

Returns the value of attribute groups.



306
307
308
# File 'lib/ridl/optparse_ext.rb', line 306

def groups
  @groups
end

#separatorObject (readonly)

Returns the value of attribute separator.



305
306
307
# File 'lib/ridl/optparse_ext.rb', line 305

def separator
  @separator
end

#switchObject (readonly)

Returns the value of attribute switch.



303
304
305
# File 'lib/ridl/optparse_ext.rb', line 303

def switch
  @switch
end

#typeObject (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, options)
  unless @groups.values.inject(false) {|f, h| h.run(arg, options) || f }
    raise ArgumentError, "unknown option [#{arg}] for switch '#{@switch}'"
  end
end