Class: Sigma::Tokens
- Inherits:
-
Object
- Object
- Sigma::Tokens
- Extended by:
- FFI::Library
- Defined in:
- lib/sigma/token.rb
Overview
An ordered collection of Token
Instance Attribute Summary collapse
-
#pointer ⇒ Object
Returns the value of attribute pointer.
Class Method Summary collapse
-
.create ⇒ Tokens
Create an empty collection.
-
.with_raw_pointer(tokens_ptr) ⇒ Tokens
Takes ownership of an existing Tokens Pointer.
Instance Method Summary collapse
-
#add(token) ⇒ Object
Add to collection.
-
#get(index) ⇒ Tokens?
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.
227 228 229 |
# File 'lib/sigma/token.rb', line 227 def pointer @pointer end |
Class Method Details
.create ⇒ Tokens
Create an empty collection
231 232 233 234 235 |
# File 'lib/sigma/token.rb', line 231 def self.create pointer = FFI::MemoryPointer.new(:pointer) ergo_lib_tokens_new(pointer) init(pointer) end |
.with_raw_pointer(tokens_ptr) ⇒ Tokens
Note:
A user of sigma_rb generally does not need to call this function
Takes ownership of an existing Tokens Pointer.
241 242 243 |
# File 'lib/sigma/token.rb', line 241 def self.with_raw_pointer(tokens_ptr) init(tokens_ptr) end |
Instance Method Details
#add(token) ⇒ Object
Add to collection
267 268 269 270 |
# File 'lib/sigma/token.rb', line 267 def add(token) error = ergo_lib_tokens_add(token.pointer, self.pointer) Util.check_error!(error) end |
#get(index) ⇒ Tokens?
Get item at specified index or return nil if no item exists
254 255 256 257 258 259 260 261 262 263 |
# File 'lib/sigma/token.rb', line 254 def get(index) token_pointer = FFI::MemoryPointer.new(:pointer) res = ergo_lib_tokens_get(self.pointer, index, token_pointer) Util.check_error!(res[:error]) if res[:is_some] Sigma::Token.with_raw_pointer(token_pointer) else nil end end |
#len ⇒ Integer
Get length of collection
247 248 249 |
# File 'lib/sigma/token.rb', line 247 def len ergo_lib_tokens_len(self.pointer) end |