Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/string.rb

Overview

This class provides additional methods to the standard Ruby String class, allowing for the removal of ANSI codes, and conversion to Key, Question, and Message objects.

Instance Method Summary collapse

Instance Method Details

#remove_ansiString

Removes ANSI escape codes from the string.

Returns:

  • (String)

    a new string with ANSI codes removed.



15
16
17
# File 'lib/utils/string.rb', line 15

def remove_ansi
  ANSI.remove_from_string(self)
end

#to_keyKey

Converts the string to a Key object.

Returns:

  • (Key)

    a new Key object initialized with the string.



22
23
24
# File 'lib/utils/string.rb', line 22

def to_key
  Key.new(self)
end

#to_message(replaces: nil) ⇒ Message

Converts the string to a Message object.

Parameters:

  • replaces (Hash, nil) (defaults to: nil)

    optional replacements to be applied in the message.

Returns:

  • (Message)

    a new Message object initialized with the string and optional replacements.



37
38
39
# File 'lib/utils/string.rb', line 37

def to_message(replaces: nil)
  Message.new(self, replaces: replaces)
end

#to_questionQuestion

Converts the string to a Question object.

Returns:

  • (Question)

    a new Question object initialized with the string.



29
30
31
# File 'lib/utils/string.rb', line 29

def to_question
  Question.new(self)
end