Sha256: 597b76ae8e814f77a62153e1f9830c92a34107104d3f6205210eae1b946f6cc6
Contents?: true
Size: 1015 Bytes
Versions: 4
Compression:
Stored size: 1015 Bytes
Contents
module DaruLite # @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..].each do |val| if val grouped << [val] else grouped.last << val end end grouped.flat_map do |items| [[items.first, items.count], *Array.new(items.count - 1)] end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
daru_lite-0.1.3 | lib/daru_lite/iruby/helpers.rb |
daru_lite-0.1.2 | lib/daru_lite/iruby/helpers.rb |
daru_lite-0.1.1 | lib/daru_lite/iruby/helpers.rb |
daru_lite-0.1 | lib/daru_lite/iruby/helpers.rb |