Class: TgMq::Frame
- Inherits:
-
Object
- Object
- TgMq::Frame
- 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
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#chunk ⇒ Object
readonly
Returns the value of attribute chunk.
-
#msg_id ⇒ Object
readonly
Returns the value of attribute msg_id.
-
#num ⇒ Object
readonly
Returns the value of attribute num.
-
#seq ⇒ Object
readonly
Returns the value of attribute seq.
Class Method Summary collapse
Instance Method Summary collapse
- #data ⇒ Object
- #id ⇒ Object
-
#initialize(seq, msg_id, num, chunk) ⇒ Frame
constructor
A new instance of Frame.
- #message_id ⇒ Object
- #set_callback(&callback) ⇒ Object
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
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
9 10 11 |
# File 'lib/tg_mq/frame.rb', line 9 def callback @callback end |
#chunk ⇒ Object (readonly)
Returns the value of attribute chunk.
9 10 11 |
# File 'lib/tg_mq/frame.rb', line 9 def chunk @chunk end |
#msg_id ⇒ Object (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 |
#num ⇒ Object (readonly)
Returns the value of attribute num.
9 10 11 |
# File 'lib/tg_mq/frame.rb', line 9 def num @num end |
#seq ⇒ Object (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
#data ⇒ Object
32 33 34 |
# File 'lib/tg_mq/frame.rb', line 32 def data "#{BEGIN_MSG}[#{id}]#{chunk}" end |
#id ⇒ Object
24 25 26 |
# File 'lib/tg_mq/frame.rb', line 24 def id "#{message_id}:#{num}" end |
#message_id ⇒ Object
28 29 30 |
# File 'lib/tg_mq/frame.rb', line 28 def "#{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 |