Class: CZTop::Config::CommentsAccessor

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/cztop/config/comments.rb

Overview

Used to access a CZTop::Config‘s comments.

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ CommentsAccessor

Returns a new instance of CommentsAccessor.

Parameters:



18
19
20
# File 'lib/cztop/config/comments.rb', line 18

def initialize(config)
  @config = config
end

Instance Method Details

#<<(new_comment) ⇒ self

Adds a new comment.

Parameters:

  • new_comment (String)

Returns:

  • (self)


25
26
27
28
# File 'lib/cztop/config/comments.rb', line 25

def <<(new_comment)
  @config.ffi_delegate.set_comment("%s", :string, new_comment)
  return self
end

#_zlistCZMQ::FFI::Zlist (private)

Returns the Zlist to the list of comments for this config item.

Returns:

  • (CZMQ::FFI::Zlist)

    the zlist of comments for this config item



61
62
63
# File 'lib/cztop/config/comments.rb', line 61

def _zlist
  @config.ffi_delegate.comments
end

#delete_allvoid

This method returns an undefined value.

Deletes all comments for this CZTop::Config item.



32
33
34
# File 'lib/cztop/config/comments.rb', line 32

def delete_all
  @config.ffi_delegate.set_comment(nil)
end

#each {|comment| ... } ⇒ void

This method returns an undefined value.

Yields all comments for this CZTop::Config item.

Yield Parameters:

  • comment (String)


39
40
41
42
43
44
45
46
47
# File 'lib/cztop/config/comments.rb', line 39

def each
  while comment = _zlist.next
    break if comment.null?
    yield comment.read_string
  end
rescue CZMQ::FFI::Zlist::DestroyedError
  # there are no comments
  nil
end

#sizeInteger

Returns the number of comments for this CZTop::Config item.

Returns:

  • (Integer)

    number of comments



51
52
53
54
55
# File 'lib/cztop/config/comments.rb', line 51

def size
  _zlist.size
rescue CZMQ::FFI::Zlist::DestroyedError
  0
end