Class: KBRecnoIndex
- Includes:
- KBEncryptionMixin
- Defined in:
- lib/kirbybase.rb
Overview
KBRecnoIndex
Constant Summary
Constants included from KBEncryptionMixin
KBEncryptionMixin::EN_KEY, KBEncryptionMixin::EN_KEY1, KBEncryptionMixin::EN_KEY_LEN, KBEncryptionMixin::EN_STR, KBEncryptionMixin::EN_STR_LEN
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 ———————————————————————–.
Methods included from KBEncryptionMixin
Constructor Details
#initialize(table) ⇒ KBRecnoIndex
initialize
3531 3532 3533 3534 |
# File 'lib/kirbybase.rb', line 3531 def initialize(table) @idx_hash = {} @table = table end |
Instance Method Details
#add_index_rec(recno, fpos) ⇒ Object
add_index_rec
3581 3582 3583 3584 3585 |
# File 'lib/kirbybase.rb', line 3581 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
3599 3600 3601 3602 3603 |
# File 'lib/kirbybase.rb', line 3599 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
3539 3540 3541 |
# File 'lib/kirbybase.rb', line 3539 def get_idx return @idx_hash end |
#rebuild(fptr) ⇒ Object
rebuild
3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 |
# File 'lib/kirbybase.rb', line 3546 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
3590 3591 3592 3593 3594 |
# File 'lib/kirbybase.rb', line 3590 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 |