class Coopy::Index

Attributes

cols[RW]
hdr[RW]
height[RW]
ignore_case[RW]
ignore_whitespace[RW]
indexed_table[RW]
items[RW]
keys[RW]
top_freq[RW]
v[RW]

Public Class Methods

new(flags) click to toggle source
# File lib/lib/coopy/index.rb, line 7
def initialize(flags)
  @items = {}
  @cols = Array.new
  @keys = Array.new
  @top_freq = 0
  @height = 0
  @hdr = 0
  @ignore_whitespace = false
  @ignore_case = false
  if flags != nil 
    @ignore_whitespace = flags.ignore_whitespace
    @ignore_case = flags.ignore_case
  end
end

Public Instance Methods

add_column(i) click to toggle source
# File lib/lib/coopy/index.rb, line 38
def add_column(i)
  @cols.push(i)
end
get_table() click to toggle source
# File lib/lib/coopy/index.rb, line 124
def get_table 
  @indexed_table
end
index_table(t,hdr) click to toggle source
# File lib/lib/coopy/index.rb, line 42
def index_table(t,hdr)
  @indexed_table = t
  @hdr = hdr
  @keys[t.get_height - 1] = nil if @keys.length != t.get_height && t.get_height > 0
  begin
    _g1 = 0
    _g = t.get_height
    while(_g1 < _g) 
      i = _g1
      _g1+=1
      key = @keys[i]
      if key == nil 
        key = self.to_key(t,i)
        @keys[i] = key
      end
      item = @items[key]
      if item == nil 
        item = ::Coopy::IndexItem.new
        @items[key] = item
      end
      ct = nil
      begin
        item.lst = Array.new if item.lst == nil
        item.lst.push(i)
        ct = item.lst.length
      end
      @top_freq = ct if ct > @top_freq
    end
  end
  @height = t.get_height
end
to_key(t,i) click to toggle source
# File lib/lib/coopy/index.rb, line 74
def to_key(t,i)
  wide = nil
  if i < @hdr 
    wide = "_"
  else 
    wide = ""
  end
  @v = t.get_cell_view if @v == nil
  begin
    _g1 = 0
    _g = @cols.length
    while(_g1 < _g) 
      k = _g1
      _g1+=1
      d = t.get_cell(@cols[k],i)
      txt = @v.to_s(d)
      txt = txt.strip if @ignore_whitespace
      txt = txt.downcase if @ignore_case
      wide += " // " if k > 0
      next if txt == nil || txt == "" || txt == "null" || txt == "undefined"
      wide += txt
    end
  end
  wide
end
to_key_by_content(row) click to toggle source
# File lib/lib/coopy/index.rb, line 100
def to_key_by_content(row)
  wide = nil
  if row.is_preamble 
    wide = "_"
  else 
    wide = ""
  end
  begin
    _g1 = 0
    _g = @cols.length
    while(_g1 < _g) 
      k = _g1
      _g1+=1
      txt = row.get_row_string(@cols[k])
      txt = txt.strip if @ignore_whitespace
      txt = txt.downcase if @ignore_case
      wide += " // " if k > 0
      next if txt == nil || txt == "" || txt == "null" || txt == "undefined"
      wide += txt
    end
  end
  wide
end