Sha256: 5c89a1d7459806feab9401bd3978ce1caa87fc519dcd6db7b9e1d94a2f212bf2

Contents?: true

Size: 901 Bytes

Versions: 1

Compression:

Stored size: 901 Bytes

Contents

module Gritano
  module CLI
    module Renderer
      def render_text(text)
        puts text
      end

      def render_table(elements, *attributes)
        attributes_hash = {}
        attributes.each do |a|
          if a.respond_to?(:keys)
            attributes_hash = attributes_hash.merge(a)
          else
            attributes_hash[a] = nil
          end
        end
        table = Terminal::Table.new do |t|
          t << attributes_hash.map { |key, value| key }
          t << :separator
          elements.each do |element|
            row = []
            attributes_hash.each do |attribute, params|
              if params
                row << element.send(attribute, params)
              else
                row << element.send(attribute)
              end
            end
            t.add_row row
          end
        end
        render_text table
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gritano-2.0.0 lib/gritano/renderer.rb