Sha256: 1f0fc25fb8f2b23df0d1c931822ab45fb9c6d050da840ca028033657017121ba

Contents?: true

Size: 620 Bytes

Versions: 13

Compression:

Stored size: 620 Bytes

Contents

module ThreeScaleToolbox
  module CLI
    class CustomTablePrinter
      attr_reader :fields

      def initialize(fields)
        @fields = fields
      end

      def print_record(record)
        print_collection([record])
      end

      def print_collection(collection)
        print_header
        print_data(collection)
      end

      private

      def print_header
        puts fields.map(&:upcase).join("\t")
      end

      def print_data(collection)
        collection.each do |obj|
          puts fields.map { |field| obj.fetch(field, '(empty)').to_s }.join("\t")
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
3scale_toolbox-1.0.1 lib/3scale_toolbox/cli/custom_table_printer.rb
3scale_toolbox-1.0.0 lib/3scale_toolbox/cli/custom_table_printer.rb
3scale_toolbox-0.20.0 lib/3scale_toolbox/cli/custom_table_printer.rb
3scale_toolbox-0.19.3 lib/3scale_toolbox/cli/custom_table_printer.rb
3scale_toolbox-0.19.2 lib/3scale_toolbox/cli/custom_table_printer.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/cli/custom_table_printer.rb
3scale_toolbox-0.19.0 lib/3scale_toolbox/cli/custom_table_printer.rb
3scale_toolbox-0.18.3 lib/3scale_toolbox/cli/custom_table_printer.rb
3scale_toolbox-0.18.2 lib/3scale_toolbox/cli/custom_table_printer.rb
3scale_toolbox-0.18.0 lib/3scale_toolbox/cli/custom_table_printer.rb
3scale_toolbox-0.17.1 lib/3scale_toolbox/cli/custom_table_printer.rb
3scale_toolbox-0.17.0 lib/3scale_toolbox/cli/custom_table_printer.rb
3scale_toolbox-0.16.0 lib/3scale_toolbox/cli/custom_table_printer.rb