Class: KBRecnoIndex

Inherits:
Object show all
Defined in:
lib/og/vendor/kirbybase.rb

Overview


KBRecnoIndex


Instance Method Summary collapse

Constructor Details

#initialize(table) ⇒ KBRecnoIndex


initialize




2619
2620
2621
2622
# File 'lib/og/vendor/kirbybase.rb', line 2619

def initialize(table)
    @idx_hash = {}
    @table = table
end

Instance Method Details

#add_index_rec(recno, fpos) ⇒ Object


add_index_rec




2669
2670
2671
2672
2673
# File 'lib/og/vendor/kirbybase.rb', line 2669

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




2687
2688
2689
2690
2691
# File 'lib/og/vendor/kirbybase.rb', line 2687

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_idxObject


get_idx




2627
2628
2629
# File 'lib/og/vendor/kirbybase.rb', line 2627

def get_idx
    return @idx_hash
end

#rebuild(fptr) ⇒ Object


rebuild




2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
# File 'lib/og/vendor/kirbybase.rb', line 2634

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




2678
2679
2680
2681
2682
# File 'lib/og/vendor/kirbybase.rb', line 2678

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