Class: IDL::OptionList::Option::Group

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

Defined Under Namespace

Classes: Configurator, ParamSet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, options) ⇒ Group

Returns a new instance of Group.



200
201
202
203
204
205
206
207
# File 'lib/ridl/optparse_ext.rb', line 200

def initialize(id, options)
  @test = options[:test] || true
  @description = Array === options[:description] ? options[:description] : (options[:description] || '').split('\n')
  @sets = {}
  if options[:params] && Hash === options[:params]
    @sets[id] = ParamSet.new(:params => options[:params])
  end
end

Instance Attribute Details

#setsObject (readonly)

Configurator



199
200
201
# File 'lib/ridl/optparse_ext.rb', line 199

def sets
  @sets
end

Instance Method Details

#descriptionObject



209
210
211
# File 'lib/ridl/optparse_ext.rb', line 209

def description
  @sets.values.inject(@description.dup) {|desc, a| desc.concat(a.description) }
end

#run(arg, options) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/ridl/optparse_ext.rb', line 213

def run(arg, options)
  ext_args = []
  if self.respond_to?(:_prepare, true)
    result = _prepare(arg, options)
    return false unless result && !result.empty?
    arg = result.shift
    ext_args = result
  else
    case @test
    when TrueClass
    when Regexp
      return false unless @test =~ arg
    else
      return false unless @test == arg
    end
  end
  return handle_sets(arg, options, *ext_args)
end