Module: Inquirex::Transcript

Defined in:
lib/inquirex/transcript.rb

Overview

Formats what the user actually saw into the prose entries a :text accumulator collects.

The Engine appends one entry per interaction — an answered question, a skipped question, a display step advanced past — and never for a step the engine elided on its own. A step removed by skip_if, or auto-skipped because an extraction already answered it, was never on screen, so it must not appear in a narrative that claims to be a record of the session.

Entries are plain prose rather than JSON because their only consumer is an LLM prompt: Q: / A: reads as dialogue to a model, where a serialized answers hash reads as data and produces a summary that sounds like one.

Constant Summary collapse

SKIPPED =

Shown instead of an answer for a question the user declined.

"(skipped)"
NO_ANSWER =

Shown instead of an answer when a step somehow carries none.

"(no answer)"

Class Method Summary collapse

Class Method Details

.answer_entry(node, answer) ⇒ String?

The entry for a question the user answered.

Parameters:

  • node (Node)

    the collecting step

  • answer (Object)

    the value the user submitted

Returns:

  • (String, nil)

    nil when the step carries no question text



39
40
41
# File 'lib/inquirex/transcript.rb', line 39

def answer_entry(node, answer)
  exchange(node, format_answer(answer, node))
end

.display_entry(node) ⇒ String?

The entry for a display step (say/header/btw/warning) the user has just advanced past: its text, verbatim.

Parameters:

  • node (Node)

    the display step

Returns:

  • (String, nil)

    nil when the step carries no text



29
30
31
32
# File 'lib/inquirex/transcript.rb', line 29

def display_entry(node)
  text = node.text.to_s.strip
  text.empty? ? nil : text
end

.format_answer(answer, node = nil) ⇒ String

Renders an answer the way it was shown, not the way it is stored: option values become their labels where the step declares them, so the narrative reads "Married filing jointly" rather than "married_filing_jointly".

Parameters:

  • answer (Object)

    a stored answer value

  • node (Node, nil) (defaults to: nil)

    the step it belongs to, for label lookup

Returns:

  • (String)


59
60
61
62
63
64
65
66
67
# File 'lib/inquirex/transcript.rb', line 59

def format_answer(answer, node = nil)
  case answer
  when nil        then NO_ANSWER
  when true       then "Yes"
  when false      then "No"
  when Array      then format_array(answer, node)
  else                 label_for(answer, node)
  end
end

.skipped_entry(node) ⇒ String?

The entry for an optional question the user declined.

Parameters:

  • node (Node)

    the collecting step

Returns:

  • (String, nil)

    nil when the step carries no question text



47
48
49
# File 'lib/inquirex/transcript.rb', line 47

def skipped_entry(node)
  exchange(node, SKIPPED)
end