Method: Array#subset

Defined in:
lib/rwd/ruby.rb

#subset(fields, values, results, exact = true, emptyline = nil, joinwith = nil) ⇒ Object



390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# File 'lib/rwd/ruby.rb', line 390

def subset(fields, values, results, exact=true, emptyline=nil, joinwith=nil)
  fields	= [fields]		unless fields.kind_of? Array
  values	= [values]		unless values.kind_of? Array
  results	= [results]		unless results.kind_of? Array
  emptyline	= emptyline.downcase	unless emptyline.nil?
  res		= self.dup
  res.delete_if {true}

  self.each do |l|
    ok	= true

    case l.class.to_s
    when "String"
      c		= l.splitwords
      correction	= 1
      joinwith	= " "	if joinwith.nil?
    when "Array"
      c		= l
      correction	= 0
    end

    #catch :stop do
      values2	= values.dup
      fields.each do |f|
        v	= values2.shift
        v	= v.downcase	unless v.nil?
        if emptyline.nil? or (not v == emptyline)
          if exact
            unless (v.nil? or c[f-correction].downcase == v)
              ok	= false
              #throw :stop
            end
          else
            unless (v.nil? or c[f-correction].downcase.include?(v))
              ok	= false
              #throw :stop
            end
          end
        end
      end
    #end

    if ok
      res2	= []
      results.each do |n|
        res2 << c[n-1]
      end
      res2	= res2.join(joinwith)	unless joinwith.nil?
      res << res2
    end
  end

  return res
end