Class: Mchat::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/mchat/comps/message.rb

Instance Method Summary collapse

Constructor Details

#initialize(message, format = :std) ⇒ Message

Returns a new instance of Message.



3
4
5
6
# File 'lib/mchat/comps/message.rb', line 3

def initialize(message, format = :std)
  @message = message
  @format = format
end

Instance Method Details

#displayObject



8
9
10
11
12
13
14
15
16
# File 'lib/mchat/comps/message.rb', line 8

def display
  if @format == :std
    # Time format https://devdocs.io/ruby~3/datetime#method-i-strftime
    tstring = Time.at(@message['timestamp'].to_i).strftime("%H:%M:%S")
    username = @message['user_name']
    content = @message['content']
    "[#{tstring.style.sea}] #{username.style.jade}: #{content.strip}\n"
  end
end