Class: Message
- Inherits:
-
Object
- Object
- Message
- Defined in:
- lib/utils/message.rb,
lib/utils/message.rb
Overview
Private Methods
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.
24 25 26 27 28 29 |
# File 'lib/utils/message.rb', line 24 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.
18 19 20 |
# File 'lib/utils/message.rb', line 18 def @message end |
Instance Method Details
#==(other) ⇒ Boolean
Compares two Message instances for equality based on their message content.
35 36 37 |
# File 'lib/utils/message.rb', line 35 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.
45 46 47 48 |
# File 'lib/utils/message.rb', line 45 def to_s = (String.new(@message)) replace_all_to_replace_elements() end |