Module: Bmg::Sql::Processor::Transform::SplitSupported

Extended by:
SplitSupported
Included in:
SplitSupported
Defined in:
lib/bmg/sql/processor/transform.rb

Instance Method Summary collapse

Instance Method Details

#_split_supported(tr, &bl) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/bmg/sql/processor/transform.rb', line 33

def _split_supported(tr, &bl)
  if tr.is_a?(Array)
    split_supported(tr, &bl)
  else
    bl.call(tr) ? [tr, nil] : [nil, tr]
  end
end

#split_supported(tr, &bl) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bmg/sql/processor/transform.rb', line 9

def split_supported(tr, &bl)
  case tr
  when Array
    i = tr.find_index{|x| !bl.call(x) } || tr.size
    [tr[0...i], tr[i..-1]].map{|a|
      case a.size
      when 0 then nil
      when 1 then a.first
      else a
      end
    }
  when Hash
    tr.inject([{}, {}]){|(sup,unsup),(k,v)|
      mine, hers = _split_supported(v, &bl)
      [
        sup.merge(k => mine),
        unsup.merge(k => hers)
      ].map(&:compact)
    }.map{|h| h.empty? ? nil : h }
  else
    _split_supported(tr, &bl)
  end
end