Sha256: b801244ced47a2c350bbc63adaa800bf7175d3c891a1aa333a99565d949ff8e7

Contents?: true

Size: 1.03 KB

Versions: 22

Compression:

Stored size: 1.03 KB

Contents

module Coltrane
  module Renderers
    module TextRenderer
      class ArrayDrawer < BaseDrawer
        alias array model

        def render
          public_send("render_#{layout}")
        end

        def renders
          @renders ||= array.map {|it| TextRenderer.render(it, **options) }
        end

        def render_vertical
          renders.join("\n")
        end

        def render_horizontal
          array
          .each_slice(per_row)
          .map { |row|
            row
            .map { |element|
              TextRenderer.render(element, **options)
              .split("\n")
              .yield_self { |lines|
                lines
                .map { |l| l.gsub(/\e\[(\d+)(;\d+)*m/, '').size }
                .max
                .yield_self { |column_w|
                  lines
                  .map { |l| l.ljust(column_w) }
                  .+([' ' * column_w])
                }
              }
            }
            .transpose
            .map(&:join)
          }.join("\n")
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
coltrane-4.1.2 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-4.1.1 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-4.1.0 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-4.0.6 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-4.0.5 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-4.0.4 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-4.0.3 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-3.4.2 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-3.4.1 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-3.4.0 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-3.3.3 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-3.3.2 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-3.3.1 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-3.3.0 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-3.2.0 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-3.1.3 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-3.1.2 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-3.1.1 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-3.1.0 lib/coltrane/renderers/text_renderer/array_drawer.rb
coltrane-3.0.0 lib/coltrane/renderers/text_renderer/array_drawer.rb