Class: Coopy::Index

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flags) ⇒ Index

Returns a new instance of Index.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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

Instance Attribute Details

#heightObject

Returns the value of attribute height.



25
26
27
# File 'lib/lib/coopy/index.rb', line 25

def height
  @height
end

#itemsObject

Returns the value of attribute items.



22
23
24
# File 'lib/lib/coopy/index.rb', line 22

def items
  @items
end

#keysObject

Returns the value of attribute keys.



23
24
25
# File 'lib/lib/coopy/index.rb', line 23

def keys
  @keys
end

#top_freqObject

Returns the value of attribute top_freq.



24
25
26
# File 'lib/lib/coopy/index.rb', line 24

def top_freq
  @top_freq
end

Instance Method Details

#add_column(i) ⇒ Object



38
39
40
# File 'lib/lib/coopy/index.rb', line 38

def add_column(i)
  @cols.push(i)
end

#get_tableObject



124
125
126
# File 'lib/lib/coopy/index.rb', line 124

def get_table 
  @indexed_table
end

#index_table(t, hdr) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# 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) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# 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