Class: Coopy::SimpleTable
- Inherits:
-
Object
- Object
- Coopy::SimpleTable
- Defined in:
- lib/lib/coopy/simple_table.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
protected - in ruby this doesn’t play well with static/inline methods.
-
#h ⇒ Object
Returns the value of attribute h.
-
#w ⇒ Object
Returns the value of attribute w.
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
- #get_cell(x, y) ⇒ Object
- #get_cell_view ⇒ Object
- #get_height ⇒ Object
- #get_size ⇒ Object
- #get_table ⇒ Object
- #get_width ⇒ Object
- #height ⇒ Object
- #height=(__v) ⇒ Object
-
#initialize(w, h) ⇒ SimpleTable
constructor
A new instance of SimpleTable.
- #insert_or_delete_columns(fate, wfate) ⇒ Object
- #insert_or_delete_rows(fate, hfate) ⇒ Object
- #is_resizable ⇒ Object
- #resize(w, h) ⇒ Object
- #set_cell(x, y, c) ⇒ Object
- #size ⇒ Object
- #size=(__v) ⇒ Object
- #to_s ⇒ Object
- #trim_blank ⇒ Object
- #width ⇒ Object
- #width=(__v) ⇒ Object
Constructor Details
#initialize(w, h) ⇒ SimpleTable
Returns a new instance of SimpleTable.
7 8 9 10 11 |
# File 'lib/lib/coopy/simple_table.rb', line 7 def initialize(w,h) @data = {} @w = w @h = h end |
Instance Attribute Details
#data ⇒ Object
protected - in ruby this doesn’t play well with static/inline methods
15 16 17 |
# File 'lib/lib/coopy/simple_table.rb', line 15 def data @data end |
#h ⇒ Object
Returns the value of attribute h.
17 18 19 |
# File 'lib/lib/coopy/simple_table.rb', line 17 def h @h end |
#w ⇒ Object
Returns the value of attribute w.
16 17 18 |
# File 'lib/lib/coopy/simple_table.rb', line 16 def w @w end |
Class Method Details
.table_to_string(tab) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/lib/coopy/simple_table.rb', line 213 def SimpleTable.table_to_string(tab) x = "" begin _g1 = 0 _g = tab.get_height while(_g1 < _g) i = _g1 _g1+=1 begin _g3 = 0 _g2 = tab.get_width while(_g3 < _g2) j = _g3 _g3+=1 x += " " if j > 0 begin s = tab.get_cell(j,i) x += s.to_s end end end x += "\n" end end return x end |
Instance Method Details
#clear ⇒ Object
74 75 76 |
# File 'lib/lib/coopy/simple_table.rb', line 74 def clear @data = {} end |
#get_cell(x, y) ⇒ Object
44 45 46 |
# File 'lib/lib/coopy/simple_table.rb', line 44 def get_cell(x,y) return @data[x + y * @w] end |
#get_cell_view ⇒ Object
60 61 62 |
# File 'lib/lib/coopy/simple_table.rb', line 60 def get_cell_view return ::Coopy::SimpleView.new end |
#get_height ⇒ Object
36 37 38 |
# File 'lib/lib/coopy/simple_table.rb', line 36 def get_height return @h end |
#get_size ⇒ Object
40 41 42 |
# File 'lib/lib/coopy/simple_table.rb', line 40 def get_size return @h end |
#get_table ⇒ Object
21 22 23 |
# File 'lib/lib/coopy/simple_table.rb', line 21 def get_table return self end |
#get_width ⇒ Object
32 33 34 |
# File 'lib/lib/coopy/simple_table.rb', line 32 def get_width return @w end |
#height ⇒ Object
25 |
# File 'lib/lib/coopy/simple_table.rb', line 25 def height() get_height end |
#height=(__v) ⇒ Object
26 |
# File 'lib/lib/coopy/simple_table.rb', line 26 def height=(__v) @height = __v end |
#insert_or_delete_columns(fate, wfate) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/lib/coopy/simple_table.rb', line 110 def insert_or_delete_columns(fate,wfate) data2 = {} begin _g1 = 0 _g = fate.length while(_g1 < _g) i = _g1 _g1+=1 j = fate[i] if j != -1 _g3 = 0 _g2 = @h while(_g3 < _g2) r = _g3 _g3+=1 idx = r * @w + i if @data.include?(idx) value = @data[idx] begin value1 = value data2[r * wfate + j] = value1 end end end end end end @w = wfate @data = data2 return true end |
#insert_or_delete_rows(fate, hfate) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/lib/coopy/simple_table.rb', line 78 def insert_or_delete_rows(fate,hfate) data2 = {} begin _g1 = 0 _g = fate.length while(_g1 < _g) i = _g1 _g1+=1 j = fate[i] if j != -1 _g3 = 0 _g2 = @w while(_g3 < _g2) c = _g3 _g3+=1 idx = i * @w + c if @data.include?(idx) value = @data[idx] begin value1 = value data2[j * @w + c] = value1 end end end end end end @h = hfate @data = data2 return true end |
#is_resizable ⇒ Object
64 65 66 |
# File 'lib/lib/coopy/simple_table.rb', line 64 def is_resizable return true end |
#resize(w, h) ⇒ Object
68 69 70 71 72 |
# File 'lib/lib/coopy/simple_table.rb', line 68 def resize(w,h) @w = w @h = h return true end |
#set_cell(x, y, c) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/lib/coopy/simple_table.rb', line 48 def set_cell(x,y,c) value = c begin value1 = value @data[x + y * @w] = value1 end end |
#size ⇒ Object
29 |
# File 'lib/lib/coopy/simple_table.rb', line 29 def size() get_size end |
#size=(__v) ⇒ Object
30 |
# File 'lib/lib/coopy/simple_table.rb', line 30 def size=(__v) @size = __v end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/lib/coopy/simple_table.rb', line 56 def to_s return ::Coopy::SimpleTable.table_to_string(self) end |
#trim_blank ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/lib/coopy/simple_table.rb', line 142 def trim_blank return true if @h == 0 h_test = @h h_test = 3 if h_test >= 3 view = self.get_cell_view space = view.to_datum("") more = true while(more) begin _g1 = 0 _g = self.get_width while(_g1 < _g) i = _g1 _g1+=1 c = self.get_cell(i,@h - 1) if !(view.equals(c,space) || c == nil) more = false break end end end @h-=1 if more end more = true nw = @w while(more) break if @w == 0 begin _g2 = 0 while(_g2 < h_test) i1 = _g2 _g2+=1 c1 = self.get_cell(nw - 1,i1) if !(view.equals(c1,space) || c1 == nil) more = false break end end end nw-=1 if more end return true if nw == @w data2 = {} begin _g3 = 0 while(_g3 < nw) i2 = _g3 _g3+=1 begin _g21 = 0 _g11 = @h while(_g21 < _g11) r = _g21 _g21+=1 idx = r * @w + i2 if @data.include?(idx) value = @data[idx] begin value1 = value data2[r * nw + i2] = value1 end end end end end end @w = nw @data = data2 return true end |
#width ⇒ Object
27 |
# File 'lib/lib/coopy/simple_table.rb', line 27 def width() get_width end |
#width=(__v) ⇒ Object
28 |
# File 'lib/lib/coopy/simple_table.rb', line 28 def width=(__v) @width = __v end |