Class: KBRecnoIndex
Overview
KBRecnoIndex
Instance Method Summary collapse
-
#add_index_rec(recno, fpos) ⇒ Object
———————————————————————– add_index_rec ———————————————————————–.
-
#delete_index_rec(recno) ⇒ Object
———————————————————————– delete_index_rec ———————————————————————–.
-
#get_idx ⇒ Object
———————————————————————– get_idx ———————————————————————–.
-
#initialize(table) ⇒ KBRecnoIndex
constructor
———————————————————————– initialize ———————————————————————–.
-
#rebuild(fptr) ⇒ Object
———————————————————————– rebuild ———————————————————————–.
-
#update_index_rec(recno, fpos) ⇒ Object
———————————————————————– update_index_rec ———————————————————————–.
Constructor Details
#initialize(table) ⇒ KBRecnoIndex
initialize
2468 2469 2470 2471 |
# File 'lib/vendor/kirbybase.rb', line 2468 def initialize(table) @idx_hash = {} @table = table end |
Instance Method Details
#add_index_rec(recno, fpos) ⇒ Object
add_index_rec
2518 2519 2520 2521 2522 |
# File 'lib/vendor/kirbybase.rb', line 2518 def add_index_rec(recno, fpos) raise 'Table already has index record for recno: %s' % recno if \ @idx_hash.has_key?(recno.to_i) @idx_hash[recno.to_i] = fpos end |
#delete_index_rec(recno) ⇒ Object
delete_index_rec
2536 2537 2538 2539 2540 |
# File 'lib/vendor/kirbybase.rb', line 2536 def delete_index_rec(recno) raise 'Table has no index record for recno: %s' % recno unless \ @idx_hash.has_key?(recno.to_i) @idx_hash.delete(recno.to_i) end |
#get_idx ⇒ Object
get_idx
2476 2477 2478 |
# File 'lib/vendor/kirbybase.rb', line 2476 def get_idx return @idx_hash end |
#rebuild(fptr) ⇒ Object
rebuild
2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 |
# File 'lib/vendor/kirbybase.rb', line 2483 def rebuild(fptr) @idx_hash.clear encrypted = @table.encrypted? begin # Skip header rec. fptr.readline # Loop through table. while true # Record current position in table. Then read first # detail record. fpos = fptr.tell line = fptr.readline line = unencrypt_str(line) if encrypted line.strip! # If blank line (i.e. 'deleted'), skip it. next if line == '' # Split the line up into fields. rec = line.split('|', 2) @idx_hash[rec.first.to_i] = fpos end # Here's how we break out of the loop... rescue EOFError end end |
#update_index_rec(recno, fpos) ⇒ Object
update_index_rec
2527 2528 2529 2530 2531 |
# File 'lib/vendor/kirbybase.rb', line 2527 def update_index_rec(recno, fpos) raise 'Table has no index record for recno: %s' % recno unless \ @idx_hash.has_key?(recno.to_i) @idx_hash[recno.to_i] = fpos end |