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.
514 515 516 |
# File 'lib/sigma/ergo_box.rb', line 514 def pointer @pointer end |
Class Method Details
.create ⇒ ErgoBoxes
Create an empty collection
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)
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.
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
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
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 |
#len ⇒ Integer
Get length of collection
549 550 551 |
# File 'lib/sigma/ergo_box.rb', line 549 def len ergo_lib_ergo_boxes_len(self.pointer) end |