Class: Sigma::ErgoBoxes

Inherits:
Object
  • Object
show all
Extended by:
FFI::Library
Defined in:
lib/sigma/ergo_box.rb

Overview

An ordered collection of ErgoBox

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pointerObject

Returns the value of attribute pointer.



514
515
516
# File 'lib/sigma/ergo_box.rb', line 514

def pointer
  @pointer
end

Class Method Details

.createErgoBoxes

Create an empty collection

Returns:



526
527
528
529
530
531
# File 'lib/sigma/ergo_box.rb', line 526

def self.create
  pointer = FFI::MemoryPointer.new(:pointer)
  ergo_lib_ergo_boxes_new(pointer)

  init(pointer)
end

.from_json(array_of_json_elements) ⇒ Object

Note:

Parameter is an ARRAY of JSON Strings

Create collection from ErgoBox Array JSON (Node API)

Parameters:

  • array_of_json_elements (Array<String>)


536
537
538
539
540
541
542
543
544
545
# File 'lib/sigma/ergo_box.rb', line 536

def self.from_json(array_of_json_elements)
  boxes = array_of_json_elements.map do |json|
    Sigma::ErgoBox.with_json(json)
  end
  container = create
  boxes.each do |box|
    container.add(box)
  end
  container
end

.with_raw_pointer(unread_pointer) ⇒ ErgoBoxes

Note:

A user of sigma_rb generally does not need to call this function

Takes ownership of an existing ErgoBoxes Pointer.

Parameters:

  • pointer (FFI::MemoryPointer)

Returns:



520
521
522
# File 'lib/sigma/ergo_box.rb', line 520

def self.with_raw_pointer(unread_pointer)
  init(unread_pointer)
end

Instance Method Details

#add(ergo_box) ⇒ Object

Add to collection

Parameters:



555
556
557
# File 'lib/sigma/ergo_box.rb', line 555

def add(ergo_box)
  ergo_lib_ergo_boxes_add(ergo_box.pointer, self.pointer)
end

#get(index) ⇒ ErgoBox?

Get item at specified index or return nil if no item exists

Parameters:

  • index (Integer)

Returns:



562
563
564
565
566
567
568
569
570
571
# File 'lib/sigma/ergo_box.rb', line 562

def get(index)
  pointer = FFI::MemoryPointer.new(:pointer)
  res = ergo_lib_ergo_boxes_get(self.pointer, index, pointer)
  Util.check_error!(res[:error])
  if res[:is_some]
    Sigma::ErgoBox.with_raw_pointer(pointer)
  else
    nil
  end
end

#lenInteger

Get length of collection

Returns:

  • (Integer)


549
550
551
# File 'lib/sigma/ergo_box.rb', line 549

def len
  ergo_lib_ergo_boxes_len(self.pointer)
end