Sha256: 65569a38c0772a6f86478b08748b45d59dfa45f05c089a3dc16a56f823a2496d

Contents?: true

Size: 894 Bytes

Versions: 2

Compression:

Stored size: 894 Bytes

Contents

module CliFormat
  class Presenter
    attr_accessor :header, :rows
    def initialize(options = {})
      @options = options
      @rows = []
    end

    delegate :text,
      :empty_message,
      :empty_message=,
      :header,
      :header=,
      :show,
      to: :strategy

    def strategy
      return @strategy if @strategy
      strategy_class = begin
        "CliFormat::Presenter::#{format.camelize}".constantize
      rescue NameError => e
        default = CliFormat.default_format
        puts "WARN: format not found: #{format}. Using default format: #{default}"
        "CliFormat::Presenter::#{default.camelize}".constantize
      end
      @strategy = strategy_class.new(@options, @header, @rows)
    end

    # Formats: tabs, markdown, json, csv, table, etc
    def format
      @options[:format] || ENV["CLI_FORMAT"] || CliFormat.default_format # table
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cli-format-0.6.1 lib/cli_format/presenter.rb
cli-format-0.6.0 lib/cli_format/presenter.rb