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.



561
562
563
564
565
566
567
# File 'lib/kreator/interactive_cli.rb', line 561

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.



558
559
560
# File 'lib/kreator/interactive_cli.rb', line 558

def body
  @body
end

#expandedObject

Returns the value of attribute expanded.



559
560
561
# File 'lib/kreator/interactive_cli.rb', line 559

def expanded
  @expanded
end

#roleObject (readonly)

Returns the value of attribute role.



558
559
560
# File 'lib/kreator/interactive_cli.rb', line 558

def role
  @role
end

#titleObject (readonly)

Returns the value of attribute title.



558
559
560
# File 'lib/kreator/interactive_cli.rb', line 558

def title
  @title
end

Instance Method Details

#collapsible?Boolean

Returns:

  • (Boolean)


569
570
571
# File 'lib/kreator/interactive_cli.rb', line 569

def collapsible?
  @collapsible
end

#to_sObject



579
580
581
582
583
584
585
586
# File 'lib/kreator/interactive_cli.rb', line 579

def to_s
  return title unless collapsible?

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

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

#toggleObject



573
574
575
576
577
# File 'lib/kreator/interactive_cli.rb', line 573

def toggle
  return unless collapsible?

  @expanded = !expanded
end