Module: Railbow::AboutFormatter

Defined in:
lib/railbow/about_formatter.rb

Instance Method Summary collapse

Instance Method Details

#to_sObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/railbow/about_formatter.rb', line 9

def to_s
  return super if Railbow.plain?

  formatter = Formatters::Base.new

  columns = [
    Table::Column.new(label: "Property", sticky: true),
    Table::Column.new(label: "Value")
  ]

  rows = @@properties.map do |(name, value)|
    val = value.respond_to?(:call) ? value.call : value
    [formatter.bold(name), val.to_s]
  end

  renderer = Table::Renderer.new(
    columns: columns,
    theme: Table::Themes::PLAIN,
    compact: Railbow::Params.compact_options,
    aliases: Railbow::Config.table_aliases
  )

  output = +"\n"
  output << renderer.render(rows)
  output << "\n"
  output
end