Class: DiscourseCli::Formatter
- Inherits:
-
Object
- Object
- DiscourseCli::Formatter
- Defined in:
- lib/discourse_cli/formatter.rb
Instance Method Summary collapse
-
#initialize(output: $stdout, json: false, quiet: false) ⇒ Formatter
constructor
A new instance of Formatter.
- #print_item(item) ⇒ Object
- #print_list(items) ⇒ Object
- #print_success(message) ⇒ Object
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
#print_item(item) ⇒ Object
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 |
#print_list(items) ⇒ Object
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 |
#print_success(message) ⇒ Object
31 32 33 34 |
# File 'lib/discourse_cli/formatter.rb', line 31 def print_success() return if @quiet || @json @output.puts end |