Sha256: 4f6a3035c85c8c20d9808cdddf1e223c06d104f9ee6f88d5e9415e8c035062b8
Contents?: true
Size: 1008 Bytes
Versions: 8
Compression:
Stored size: 1008 Bytes
Contents
module Daru # @private module IRuby module Helpers module_function def tuples_with_rowspans(index) index.sparse_tuples.transpose .map { |r| nils_counted(r) } .transpose.map(&:compact) end def tuples_with_colspans(index) index.sparse_tuples.transpose .map { |r| nils_counted(r) } .map(&:compact) end # It is complicated, but the only algo I could think of. # It does [:a, nil, nil, :b, nil, :c] # => # [[:a,3], nil, nil, [:b,2], nil, :c] # Needed by tuples_with_colspans/rowspans, which we need for pretty HTML def nils_counted array grouped = [[array.first]] array[1..-1].each do |val| if val grouped << [val] else grouped.last << val end end grouped.flat_map { |items| [[items.first, items.count], *[nil] * (items.count - 1)] } end end end end
Version data entries
8 entries across 8 versions & 1 rubygems