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
|