Class: Bl::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/bl/formatter.rb

Defined Under Namespace

Modules: Format

Constant Summary collapse

TPUT_COLS =
`tput cols`.to_i

Instance Method Summary collapse

Constructor Details

#initialize(format: 'table') ⇒ Formatter

Returns a new instance of Formatter.



9
10
11
12
13
14
15
16
17
18
# File 'lib/bl/formatter.rb', line 9

def initialize(format: 'table')
  @format = case format
  when 'table'
    Format::Hirb
  when 'json'
    Format::Json
  else
    abort 'format must be set to \'table\' or \'json\''
  end
end

Instance Method Details

#render(*args) ⇒ Object



20
21
22
# File 'lib/bl/formatter.rb', line 20

def render(*args)
  @format.render(args[0], args[1].merge(max_width: TPUT_COLS))
end