Class: NWRFC::Table
- Inherits:
-
DataContainer
- Object
- DataContainer
- NWRFC::Table
- Includes:
- Enumerable
- Defined in:
- lib/nwrfc.rb
Instance Attribute Summary
Attributes inherited from DataContainer
Instance Method Summary collapse
-
#[](index) ⇒ Object
Retrieve the row at the given index.
-
#append(row) ⇒ Object
Append a row (structure) to the table.
-
#clear ⇒ Object
Delete all rows from (empty) the table.
-
#each(&block) ⇒ Object
Iterate over the rows in a table.
-
#new_row ⇒ Object
Add new (empty) row and return the structure handle or yield it to a passed block.
-
#size ⇒ Object
Return the number of rows in the table.
Methods inherited from DataContainer
#[]=, #fields, #initialize, #member_metadata, #value_to_date, #value_to_time
Constructor Details
This class inherits a constructor from NWRFC::DataContainer
Instance Method Details
#[](index) ⇒ Object
Retrieve the row at the given index
386 387 388 389 390 391 392 |
# File 'lib/nwrfc.rb', line 386 def [](index) rc = NWRFCLib.move_to(@handle, index, @error) NWRFC.check_error(@error) if rc > 0 struct_handle = NWRFCLib.get_current_row(@handle, @error) NWRFC.check_error(@error) Structure.new(struct_handle) end |
#append(row) ⇒ Object
Append a row (structure) to the table
395 396 397 398 399 |
# File 'lib/nwrfc.rb', line 395 def append(row) raise "Must append a structure" unless row.class == NWRFC::Structure rc = NWRFCLib.append_row(@handle, row.handle, @error) NWRFC.check_error(@error) if rc > 0 end |
#clear ⇒ Object
Delete all rows from (empty) the table
380 381 382 383 |
# File 'lib/nwrfc.rb', line 380 def clear rc = NWRFCLib.delete_all_rows(@handle, @error) NWRFC.check_error(@error) if rc > 0 end |
#each(&block) ⇒ Object
Iterate over the rows in a table. Each row is yielded as a structure
358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/nwrfc.rb', line 358 def each(&block) #:yields row return [] if size == 0 rc = NWRFCLib.move_to_first_row(@handle, @error) NWRFC.check_error(@error) if rc > 0 size.times do |row| struct_handle = NWRFCLib.get_current_row(@handle, @error) NWRFC.check_error(@error) NWRFCLib.move_to_next_row(@handle, @error) # CAVEAT: Other calls using the handle require "handle" field # of the RFC_DATA_CONTAINER struct yield Structure.new(struct_handle) end end |
#new_row ⇒ Object
Add new (empty) row and return the structure handle or yield it to a passed block
404 405 406 407 408 409 410 411 412 413 |
# File 'lib/nwrfc.rb', line 404 def new_row s_handle = NWRFCLib.append_new_row(@handle, @error) NWRFC.check_error(@error) s = Structure.new(s_handle) if block_given? yield s else s end end |