Class: Kreator::InteractiveCLI::TranscriptEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/kreator/interactive_cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role:, title:, body: nil, collapsible: false, expanded: false) ⇒ TranscriptEntry

Returns a new instance of TranscriptEntry.



442
443
444
445
446
447
448
# File 'lib/kreator/interactive_cli.rb', line 442

def initialize(role:, title:, body: nil, collapsible: false, expanded: false)
  @role = role
  @title = title
  @body = body.to_s
  @collapsible = collapsible
  @expanded = expanded
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



439
440
441
# File 'lib/kreator/interactive_cli.rb', line 439

def body
  @body
end

#expandedObject

Returns the value of attribute expanded.



440
441
442
# File 'lib/kreator/interactive_cli.rb', line 440

def expanded
  @expanded
end

#roleObject (readonly)

Returns the value of attribute role.



439
440
441
# File 'lib/kreator/interactive_cli.rb', line 439

def role
  @role
end

#titleObject (readonly)

Returns the value of attribute title.



439
440
441
# File 'lib/kreator/interactive_cli.rb', line 439

def title
  @title
end

Instance Method Details

#collapsible?Boolean

Returns:

  • (Boolean)


450
451
452
# File 'lib/kreator/interactive_cli.rb', line 450

def collapsible?
  @collapsible
end

#to_sObject



460
461
462
463
464
465
466
467
# File 'lib/kreator/interactive_cli.rb', line 460

def to_s
  return title unless collapsible?

  marker = expanded ? "[-]" : "[+]"
  return "#{marker} #{title}" unless expanded && !body.empty?

  "#{marker} #{title}\n#{body}"
end

#toggleObject



454
455
456
457
458
# File 'lib/kreator/interactive_cli.rb', line 454

def toggle
  return unless collapsible?

  @expanded = !expanded
end