Class: CliFormat::Presenter

Inherits:
Object
  • Object
show all
Defined in:
lib/cli_format/presenter.rb,
lib/cli_format/presenter/csv.rb,
lib/cli_format/presenter/tab.rb,
lib/cli_format/presenter/base.rb,
lib/cli_format/presenter/info.rb,
lib/cli_format/presenter/json.rb,
lib/cli_format/presenter/equal.rb,
lib/cli_format/presenter/space.rb,
lib/cli_format/presenter/table.rb,
lib/cli_format/presenter/dotenv.rb,
lib/cli_format/presenter/markdown.rb

Defined Under Namespace

Classes: Base, Csv, Dotenv, Equal, Info, Json, Markdown, Space, Tab, Table

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Presenter

Returns a new instance of Presenter.



4
5
6
7
# File 'lib/cli_format/presenter.rb', line 4

def initialize(options = {})
  @options = options
  @rows = []
end

Instance Attribute Details

#headerObject

Returns the value of attribute header.



3
4
5
# File 'lib/cli_format/presenter.rb', line 3

def header
  @header
end

#rowsObject

Returns the value of attribute rows.



3
4
5
# File 'lib/cli_format/presenter.rb', line 3

def rows
  @rows
end

Instance Method Details

#formatObject

Formats: tabs, markdown, json, csv, table, etc



30
31
32
# File 'lib/cli_format/presenter.rb', line 30

def format
  @options[:format] || ENV["CLI_FORMAT"] || CliFormat.default_format # table
end

#strategyObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cli_format/presenter.rb', line 17

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