3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/message_handler.rb', line 3
def self.handle(message)
message = JSON.parse(message) rescue ["?", message]
type = message[0]
strategy_class = case type
when 'EVENT' then EventMessageStrategy
when 'OK' then OkMessageStrategy
when 'EOSE' then EoseMessageStrategy
when 'CLOSED' then ClosedMessageStrategy
when 'NOTICE' then NoticeMessageStrategy
else UnknownMessageStrategy
end
processed_data = strategy_class.new(message).process
type == "EVENT" ? processed_data : ParsedData.new(processed_data)
end
|