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.



637
638
639
640
641
642
643
# File 'lib/kreator/interactive_cli.rb', line 637

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.



634
635
636
# File 'lib/kreator/interactive_cli.rb', line 634

def body
  @body
end

#expandedObject

Returns the value of attribute expanded.



635
636
637
# File 'lib/kreator/interactive_cli.rb', line 635

def expanded
  @expanded
end

#roleObject (readonly)

Returns the value of attribute role.



634
635
636
# File 'lib/kreator/interactive_cli.rb', line 634

def role
  @role
end

#titleObject (readonly)

Returns the value of attribute title.



634
635
636
# File 'lib/kreator/interactive_cli.rb', line 634

def title
  @title
end

Instance Method Details

#collapsible?Boolean

Returns:

  • (Boolean)


645
646
647
# File 'lib/kreator/interactive_cli.rb', line 645

def collapsible?
  @collapsible
end

#to_sObject



655
656
657
658
659
660
661
662
# File 'lib/kreator/interactive_cli.rb', line 655

def to_s
  return title unless collapsible?

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

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

#toggleObject



649
650
651
652
653
# File 'lib/kreator/interactive_cli.rb', line 649

def toggle
  return unless collapsible?

  @expanded = !expanded
end