Sha256: 91797b395ede961cffcf4ca9a8532bc099f77edb475ba8271353be4aca78ea4c

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module RocketChat
  #
  # Rocket.Chat Message
  #
  class Message
    # Raw user data
    attr_reader :data

    #
    # @param [Hash] data Raw message data
    #
    def initialize(data)
      @data = Util.stringify_hash_keys data
    end

    # Message ID
    def id
      data['_id']
    end

    # Timestamp
    def timestamp
      Time.parse data['ts']
    end

    # Updated at
    def updated_at
      Time.parse data['_updatedAt']
    end

    # Room ID
    def room_id
      data['rid']
    end

    # User
    def user
      User.new data['u']
    end

    # Message
    def message
      data['msg']
    end

    # Alias
    def alias
      data['alias']
    end

    # Parse URLs
    def parse_urls
      data['parseUrls']
    end

    # Groupable
    def groupable
      data['groupable']
    end

    def inspect
      format(
        '#<%<class_name>s:0x%<object_id>p @id="%<id>s" @room="%<room_id>s" @msg="%<message>s">',
        class_name: self.class.name,
        object_id: object_id,
        id: id,
        room_id: room_id,
        message: message
      )
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rocketchat-0.2.1 lib/rocket_chat/message.rb
rocketchat-0.1.23 lib/rocket_chat/message.rb
rocketchat-0.1.22 lib/rocket_chat/message.rb
rocketchat-0.1.21 lib/rocket_chat/message.rb
rocketchat-0.1.20 lib/rocket_chat/message.rb
rocketchat-0.1.19 lib/rocket_chat/message.rb