Class: TgMq::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/tg_mq/frame.rb

Constant Summary collapse

BEGIN_MSG =
'tgw'
BEGIN_RX =
/^#{BEGIN_MSG}\[(?<seq>\d+):(?<msg_id>\d+):(?<num>\d+)\](?<msg>.*)/
END_MSG =
':wgt'
END_RX =
/#{END_MSG}$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seq, msg_id, num, chunk) ⇒ Frame

Returns a new instance of Frame.



11
12
13
14
15
16
# File 'lib/tg_mq/frame.rb', line 11

def initialize(seq, msg_id, num, chunk)
  @seq = seq
  @msg_id = msg_id
  @num = num
  @chunk = chunk
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



9
10
11
# File 'lib/tg_mq/frame.rb', line 9

def callback
  @callback
end

#chunkObject (readonly)

Returns the value of attribute chunk.



9
10
11
# File 'lib/tg_mq/frame.rb', line 9

def chunk
  @chunk
end

#msg_idObject (readonly)

Returns the value of attribute msg_id.



9
10
11
# File 'lib/tg_mq/frame.rb', line 9

def msg_id
  @msg_id
end

#numObject (readonly)

Returns the value of attribute num.



9
10
11
# File 'lib/tg_mq/frame.rb', line 9

def num
  @num
end

#seqObject (readonly)

Returns the value of attribute seq.



9
10
11
# File 'lib/tg_mq/frame.rb', line 9

def seq
  @seq
end

Class Method Details

.parse(data) ⇒ Object



18
19
20
21
22
# File 'lib/tg_mq/frame.rb', line 18

def self.parse(data)
  if (md = BEGIN_RX.match(data))
    new(md[:seq], md[:msg_id], md[:num].to_i, md[:msg])
  end
end

Instance Method Details

#dataObject



32
33
34
# File 'lib/tg_mq/frame.rb', line 32

def data
  "#{BEGIN_MSG}[#{id}]#{chunk}"
end

#idObject



24
25
26
# File 'lib/tg_mq/frame.rb', line 24

def id
  "#{message_id}:#{num}"
end

#message_idObject



28
29
30
# File 'lib/tg_mq/frame.rb', line 28

def message_id
  "#{seq}:#{msg_id}"
end

#set_callback(&callback) ⇒ Object



36
37
38
# File 'lib/tg_mq/frame.rb', line 36

def set_callback(&callback)
  @callback = callback
end