-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage.rb
56 lines (47 loc) · 1.48 KB
/
message.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class Message
attr_accessor :data
attr_accessor :type
attr_accessor :id
attr_accessor :links
attr_accessor :attributes
attr_accessor :command
attr_accessor :room
attr_accessor :timestamp
attr_accessor :deleted
attr_accessor :message
attr_accessor :from
attr_accessor :color
attr_accessor :tags
attr_accessor :time
# "type" => "rechat-message",
# "id" => "chat-30-2016:AVYtb5WS5jaxaKEBg7jq",
# "attributes" => {
# "command" => "",
# "room" => "akiicat",
# "timestamp" => 1469624309082,
# "deleted" => false,
# "message" => "message contetn",
# "from" => "akiicat",
# "tags" => { ... },
# "color" => "#008000" },
# "links" => { "self" => "/rechat-message/chat-30-2016:AVYsb5Wc5jasaKEBg7jq" }
def initialize(data)
@data = data.to_s
@type = data["type"]
@id = data["id"]
@links = data["links"]
@attributes = data["attributes"]
@command = data["attributes"]["command"]
@room = data["attributes"]["room"]
@timestamp = data["attributes"]["timestamp"].to_i
@deleted = data["attributes"]["deleted"]
@message = data["attributes"]["message"]
@from = data["attributes"]["from"]
@color = data["attributes"]["color"]
@tags = data["attributes"]["tags"]
@time = Time.at(@timestamp/1000).to_datetime.to_s
end
def inspect
"<#{@time} #{@from}: #{@message}>"
end
end