Class: CZTop::Message::FramesAccessor
- Inherits:
-
Object
- Object
- CZTop::Message::FramesAccessor
- Includes:
- Enumerable
- Defined in:
- lib/cztop/message/frames.rb
Overview
Used to access a CZTop::Message‘s Frames.
Instance Method Summary collapse
-
#[](*args) ⇒ Frame?
Index access to a frame/frames of this message, just like with an array.
-
#each {|frame| ... } ⇒ self
Yields all frames for this message to the given block.
-
#first ⇒ Frame?
Returns the last frame of this message.
-
#initialize(message) ⇒ FramesAccessor
constructor
A new instance of FramesAccessor.
-
#last ⇒ Frame?
Returns the last frame of this message.
Constructor Details
#initialize(message) ⇒ FramesAccessor
Returns a new instance of FramesAccessor.
26 27 28 |
# File 'lib/cztop/message/frames.rb', line 26 def initialize() @message = end |
Instance Method Details
#[](index) ⇒ Frame? #[](*args) ⇒ Frame?
Index access to a frame/frames of this message, just like with an array.
61 62 63 64 65 66 67 |
# File 'lib/cztop/message/frames.rb', line 61 def [](*args) case args when [0] then first # speed up when [-1] then last # speed up else to_a[*args] end end |
#each {|frame| ... } ⇒ self
Note:
Not thread safe.
Yields all frames for this message to the given block.
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/cztop/message/frames.rb', line 74 def each first = first() return unless first yield first while (frame = @message.ffi_delegate.next) && !frame.null? yield Frame.from_ffi_delegate(frame) end self end |
#first ⇒ Frame?
Returns the last frame of this message.
34 35 36 37 38 39 |
# File 'lib/cztop/message/frames.rb', line 34 def first first = @message.ffi_delegate.first return nil if first.null? Frame.from_ffi_delegate(first) end |
#last ⇒ Frame?
Returns the last frame of this message.
45 46 47 48 49 50 |
# File 'lib/cztop/message/frames.rb', line 45 def last last = @message.ffi_delegate.last return nil if last.null? Frame.from_ffi_delegate(last) end |