Class: Waves::CLI::Formatter

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

Instance Method Summary collapse

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



16
17
18
# File 'lib/waves/cli/formatter.rb', line 16

def ()
  print_record()
end


12
13
14
# File 'lib/waves/cli/formatter.rb', line 12

def print_json(payload)
  @stdout.puts JSON.pretty_generate(payload)
end


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


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


47
48
49
# File 'lib/waves/cli/formatter.rb', line 47

def print_session(session)
  print_record(session)
end


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