Class: CZTop::Message::FramesAccessor

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/cztop/message/frames.rb

Overview

Used to access a CZTop::Message‘s Frames.

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ FramesAccessor

Returns a new instance of FramesAccessor.

Parameters:



26
27
28
# File 'lib/cztop/message/frames.rb', line 26

def initialize(message)
  @message = message
end

Instance Method Details

#[](index) ⇒ Frame? #[](*args) ⇒ Frame?

Index access to a frame/frames of this message, just like with an array.

Overloads:

  • #[](index) ⇒ Frame?

    Parameters:

  • #[](*args) ⇒ Frame?
    Note:

    See Array#[] for details.

Returns:

  • (Frame)

    frame Message

  • (nil)

    if there are no corresponding frames



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.

Yield Parameters:

Returns:

  • (self)


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

#firstFrame?

Returns the last frame of this message.

Returns:

  • (Frame)

    first frame of Message

  • (nil)

    if there are no frames



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

#lastFrame?

Returns the last frame of this message.

Returns:



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