Class: Coopy::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/coopy/index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIndex

Returns a new instance of Index.



9
10
11
12
13
14
15
16
17
# File 'lib/coopy/index.rb', line 9

def initialize
  @items = {}
  @cols = [] # Array<integer>
  @keys = []
  @top_freq = 0
  @height = 0
  @v = nil # View
  @indexed_table = nil # Table
end

Instance Attribute Details

#heightObject

integer



7
8
9
# File 'lib/coopy/index.rb', line 7

def height
  @height
end

#itemsObject

Hash<String,IndexItem>



4
5
6
# File 'lib/coopy/index.rb', line 4

def items
  @items
end

#keysObject

Array<String>



5
6
7
# File 'lib/coopy/index.rb', line 5

def keys
  @keys
end

#top_freqObject

integer



6
7
8
# File 'lib/coopy/index.rb', line 6

def top_freq
  @top_freq
end

Instance Method Details

#add_column(i) ⇒ Object



19
20
21
# File 'lib/coopy/index.rb', line 19

def add_column(i)
  @cols << i
end

#get_tableObject



68
69
70
# File 'lib/coopy/index.rb', line 68

def get_table
  @indexed_table
end

#index_table(t) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/coopy/index.rb', line 23

def index_table(t)
  @indexed_table = t
  (0...t.height).each do |i|
    key = ""
    if @keys.length > i
      key = @keys[i]
    else
      key = to_key(t,i)
      @keys << key
    end
    item = @items[key]
    if item.nil?
      item = IndexItem.new
      @items[key] = item
    end
    ct = item.add(i)
    @top_freq = ct if ct>@top_freq
  end
  @height = t.height
end

#to_key(table, i) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/coopy/index.rb', line 44

def to_key(table, i)
  wide = ""
  @v = table.get_cell_view if @v.nil?
  @cols.each_with_index do |col, k|
    d = table.get_cell(col,i)
    txt = @v.to_s(d)
    next if (txt=="" || txt=="null" || txt=="undefined")
    wide += " // " if (k>0)
    wide += txt
  end
  wide
end

#to_key_by_content(row) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/coopy/index.rb', line 57

def to_key_by_content(row)
  wide = ""
  @cols.each_with_index do |col, k|
    txt = row.get_row_string(col)
    next if (txt=="" || txt=="null" || txt=="undefined")
    wide += " // " if (k>0)
    wide += txt
  end
  wide
end