Class: Message
- Inherits:
-
Object
- Object
- Message
- Defined in:
- lib/utils/message.rb
Overview
The Message class represents a mechanism for dynamically handling and formatting messages.
It supports the substitution of placeholders within a message template with actual data.
The class leverages file-based message templates, allowing for easy localization or
customization of messages.
It integrates seamlessly with the Resources module to access these templates from a customizable path set via the "SCRIPT_CUSTOM_RESOURCES" environment variable or from a default library path.
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares two Message instances for equality based on their message content.
-
#initialize(message, replaces: nil) ⇒ Message
constructor
Initializes a new instance of the Message class with a given message template.
-
#to_s ⇒ String
Converts the message template into a string, replacing any placeholders with actual data.
Constructor Details
#initialize(message, replaces: nil) ⇒ Message
Initializes a new instance of the Message class with a given message template.
26 27 28 29 30 31 |
# File 'lib/utils/message.rb', line 26 def initialize(, replaces: nil) raise 'Messsage replaces content need be a Hash' if !replaces.nil? && !replaces.is_a?(Hash) @to_replace = replaces @message = end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
20 21 22 |
# File 'lib/utils/message.rb', line 20 def @message end |
Instance Method Details
#==(other) ⇒ Boolean
Compares two Message instances for equality based on their message content.
37 38 39 |
# File 'lib/utils/message.rb', line 37 def ==(other) self.class == other.class && @message == other. end |
#to_s ⇒ String
Converts the message template into a string, replacing any placeholders with actual data.
This method searches for keys within the message and replaces them with corresponding
content from message files located in either the custom path or the library path and appling
the given replaces.
If the file name have the suffix ".aas.txt", the ANSIStyleManager will be applied to the file.
48 49 50 51 |
# File 'lib/utils/message.rb', line 48 def to_s = (String.new(@message)) replace_all_to_replace_elements() end |