Class: Sigma::ErgoBoxes
- Inherits:
-
Object
- Object
- Sigma::ErgoBoxes
- Extended by:
- FFI::Library
- Defined in:
- lib/sigma/ergo_box.rb
Overview
An ordered collection of ErgoBox
Instance Attribute Summary collapse
-
#pointer ⇒ Object
Returns the value of attribute pointer.
Class Method Summary collapse
-
.create ⇒ ErgoBoxes
Create an empty collection.
-
.from_json(array_of_json_elements) ⇒ Object
Create collection from ErgoBox Array JSON (Node API).
-
.with_raw_pointer(unread_pointer) ⇒ ErgoBoxes
Takes ownership of an existing ErgoBoxes Pointer.
Instance Method Summary collapse
-
#add(ergo_box) ⇒ Object
Add to collection.
-
#get(index) ⇒ ErgoBox?
Get item at specified index or return nil if no item exists.
-
#len ⇒ Integer
Get length of collection.
Instance Attribute Details
#pointer ⇒ Object
Returns the value of attribute pointer.
518 519 520 |
# File 'lib/sigma/ergo_box.rb', line 518 def pointer @pointer end |
Class Method Details
.create ⇒ ErgoBoxes
Create an empty collection
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)
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.
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
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
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 |
#len ⇒ Integer
Get length of collection
553 554 555 |
# File 'lib/sigma/ergo_box.rb', line 553 def len ergo_lib_ergo_boxes_len(self.pointer) end |