Class: KBIndex
- Includes:
- KBTypeConversionsMixin
- Defined in:
- lib/og/vendor/kirbybase.rb
Overview
KBIndex
Constant Summary collapse
- UNENCODE_RE =
/&(?:amp|linefeed|carriage_return|substitute|pipe);/
Instance Method Summary collapse
-
#add_index_rec(rec) ⇒ Object
———————————————————————– add_index_rec ———————————————————————–.
-
#delete_index_rec(recno) ⇒ Object
———————————————————————– delete_index_rec ———————————————————————–.
-
#get_idx ⇒ Object
———————————————————————– get_idx ———————————————————————–.
-
#get_timestamp ⇒ Object
———————————————————————– get_timestamp ———————————————————————–.
-
#initialize(table, index_fields) ⇒ KBIndex
constructor
———————————————————————– initialize ———————————————————————–.
-
#rebuild(fptr) ⇒ Object
———————————————————————– rebuild ———————————————————————–.
-
#update_index_rec(rec) ⇒ Object
———————————————————————– update_index_rec ———————————————————————–.
Methods included from KBTypeConversionsMixin
Constructor Details
#initialize(table, index_fields) ⇒ KBIndex
initialize
2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 |
# File 'lib/og/vendor/kirbybase.rb', line 2506 def initialize(table, index_fields) @last_update = Time.new @idx_arr = [] @table = table @index_fields = index_fields @col_poss = index_fields.collect {|i| table.field_names.index(i) } @col_names = index_fields @col_types = index_fields.collect {|i| table.field_types[table.field_names.index(i)]} end |
Instance Method Details
#add_index_rec(rec) ⇒ Object
add_index_rec
2585 2586 2587 2588 2589 2590 2591 |
# File 'lib/og/vendor/kirbybase.rb', line 2585 def add_index_rec(rec) @idx_arr << @col_poss.zip(@col_types).collect do |col_pos, col_type| convert_to(col_type, rec[col_pos]) end + [rec.first.to_i] @last_update = Time.new end |
#delete_index_rec(recno) ⇒ Object
delete_index_rec
2596 2597 2598 2599 2600 |
# File 'lib/og/vendor/kirbybase.rb', line 2596 def delete_index_rec(recno) i = @idx_arr.rassoc(recno.to_i) @idx_arr.delete_at(@idx_arr.index(i)) unless i.nil? @last_update = Time.new end |
#get_idx ⇒ Object
get_idx
2520 2521 2522 |
# File 'lib/og/vendor/kirbybase.rb', line 2520 def get_idx return @idx_arr end |
#get_timestamp ⇒ Object
get_timestamp
2527 2528 2529 |
# File 'lib/og/vendor/kirbybase.rb', line 2527 def return @last_update end |
#rebuild(fptr) ⇒ Object
rebuild
2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 |
# File 'lib/og/vendor/kirbybase.rb', line 2534 def rebuild(fptr) @idx_arr.clear encrypted = @table.encrypted? # Skip header rec. fptr.readline begin # Loop through table. while true 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('|', @col_poss.max+2) # Create the index record by pulling out the record fields # that make up this index and converting them to their # native types. idx_rec = [] @col_poss.zip(@col_types).each do |col_pos, col_type| idx_rec << convert_to(col_type, rec[col_pos]) end # Were all the index fields for this record equal to NULL? # Then don't add this index record to index array; skip to # next record. next if idx_rec.compact.empty? # Add recno to the end of this index record. idx_rec << rec.first.to_i # Add index record to index array. @idx_arr << idx_rec end # Here's how we break out of the loop... rescue EOFError end @last_update = Time.new end |
#update_index_rec(rec) ⇒ Object
update_index_rec
2605 2606 2607 2608 |
# File 'lib/og/vendor/kirbybase.rb', line 2605 def update_index_rec(rec) delete_index_rec(rec.first.to_i) add_index_rec(rec) end |