Class: DiscourseCli::Formatter

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

Instance Method Summary collapse

Constructor Details

#initialize(output: $stdout, json: false, quiet: false) ⇒ Formatter

Returns a new instance of Formatter.



7
8
9
10
11
# File 'lib/discourse_cli/formatter.rb', line 7

def initialize(output: $stdout, json: false, quiet: false)
  @output = output
  @json = json
  @quiet = quiet
end

Instance Method Details



22
23
24
25
26
27
28
29
# File 'lib/discourse_cli/formatter.rb', line 22

def print_item(item)
  return if @quiet
  if @json
    @output.puts JSON.pretty_generate(item)
  else
    item.each { |k, v| @output.puts "#{k}: #{v}" }
  end
end


13
14
15
16
17
18
19
20
# File 'lib/discourse_cli/formatter.rb', line 13

def print_list(items)
  return if @quiet
  if @json
    @output.puts JSON.pretty_generate(items)
  else
    items.each { |item| @output.puts format_row(item) }
  end
end


31
32
33
34
# File 'lib/discourse_cli/formatter.rb', line 31

def print_success(message)
  return if @quiet || @json
  @output.puts message
end