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.



518
519
520
# File 'lib/sigma/ergo_box.rb', line 518

def pointer
  @pointer
end

Class Method Details

.createErgoBoxes

Create an empty collection

Returns:



530
531
532
533
534
535
# File 'lib/sigma/ergo_box.rb', line 530

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>)


540
541
542
543
544
545
546
547
548
549
# File 'lib/sigma/ergo_box.rb', line 540

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:



524
525
526
# File 'lib/sigma/ergo_box.rb', line 524

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

Instance Method Details

#add(ergo_box) ⇒ Object

Add to collection

Parameters:



559
560
561
# File 'lib/sigma/ergo_box.rb', line 559

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:



566
567
568
569
570
571
572
573
574
575
# File 'lib/sigma/ergo_box.rb', line 566

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)


553
554
555
# File 'lib/sigma/ergo_box.rb', line 553

def len
  ergo_lib_ergo_boxes_len(self.pointer)
end