Class: Waves::CLI::Formatter
- Inherits:
-
Object
- Object
- Waves::CLI::Formatter
- Defined in:
- lib/waves/cli/formatter.rb
Instance Method Summary collapse
-
#initialize(stdout:) ⇒ Formatter
constructor
A new instance of Formatter.
- #print_account(account) ⇒ Object
- #print_json(payload) ⇒ Object
- #print_list(response) ⇒ Object
- #print_search(response) ⇒ Object
- #print_session(session) ⇒ Object
- #print_transcript(response) ⇒ Object
Constructor Details
#initialize(stdout:) ⇒ Formatter
Returns a new instance of Formatter.
8 9 10 |
# File 'lib/waves/cli/formatter.rb', line 8 def initialize(stdout:) @stdout = stdout end |
Instance Method Details
#print_account(account) ⇒ Object
16 17 18 |
# File 'lib/waves/cli/formatter.rb', line 16 def print_account(account) print_record(account) end |
#print_json(payload) ⇒ Object
12 13 14 |
# File 'lib/waves/cli/formatter.rb', line 12 def print_json(payload) @stdout.puts JSON.pretty_generate(payload) end |
#print_list(response) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/waves/cli/formatter.rb', line 20 def print_list(response) sessions = Array(response["sessions"]) if sessions.empty? @stdout.puts "No sessions found" return end print_collection(sessions) return if response["next_cursor"].to_s.empty? @stdout.puts @stdout.puts "Next cursor: #{response["next_cursor"]}" end |
#print_search(response) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/waves/cli/formatter.rb', line 36 def print_search(response) results = Array(response["results"]) if results.empty? @stdout.puts "No results found" return end print_collection(results, include_snippet: true) end |
#print_session(session) ⇒ Object
47 48 49 |
# File 'lib/waves/cli/formatter.rb', line 47 def print_session(session) print_record(session) end |
#print_transcript(response) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/waves/cli/formatter.rb', line 51 def print_transcript(response) transcript = response["transcript"] case transcript when String @stdout.puts transcript when Array transcript.each do |entry| @stdout.puts transcript_line(entry) end else print_record(response) end end |