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.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#w ⇒ Object
Returns the value of attribute w.
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
- #clone ⇒ Object
- #create ⇒ Object
- #get_cell(x, y) ⇒ Object
- #get_cell_view ⇒ Object
- #get_data ⇒ Object
- #get_height ⇒ Object
- #get_meta ⇒ 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
- #set_meta(meta) ⇒ 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 12 |
# File 'lib/lib/coopy/simple_table.rb', line 7 def initialize(w,h) @data = {} @w = w @h = h = nil end |
Instance Attribute Details
#data ⇒ Object
protected - in ruby this doesn’t play well with static/inline methods
16 17 18 |
# File 'lib/lib/coopy/simple_table.rb', line 16 def data @data end |
#h ⇒ Object
Returns the value of attribute h.
18 19 20 |
# File 'lib/lib/coopy/simple_table.rb', line 18 def h @h end |
#meta ⇒ Object
Returns the value of attribute meta.
19 20 21 |
# File 'lib/lib/coopy/simple_table.rb', line 19 def end |
#w ⇒ Object
Returns the value of attribute w.
17 18 19 |
# File 'lib/lib/coopy/simple_table.rb', line 17 def w @w end |
Class Method Details
.table_is_similar(tab1, tab2) ⇒ Object
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/lib/coopy/simple_table.rb', line 313 def SimpleTable.table_is_similar(tab1,tab2) if tab1.get_height == -1 || tab2.get_height == -1 txt1 = ::Coopy::SimpleTable.table_to_string(tab1) txt2 = ::Coopy::SimpleTable.table_to_string(tab2) return txt1 == txt2 end return false if tab1.get_width != tab2.get_width return false if tab1.get_height != tab2.get_height v = tab1.get_cell_view begin _g1 = 0 _g = tab1.get_height while(_g1 < _g) i = _g1 _g1+=1 begin _g3 = 0 _g2 = tab1.get_width while(_g3 < _g2) j = _g3 _g3+=1 return false if !v.equals(tab1.get_cell(j,i),tab2.get_cell(j,i)) end end end end true end |
.table_to_string(tab) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/lib/coopy/simple_table.rb', line 248 def SimpleTable.table_to_string(tab) = tab. if != nil stream = .get_row_stream if stream != nil x = "" cols = stream.fetch_columns begin _g1 = 0 _g = cols.length while(_g1 < _g) i = _g1 _g1+=1 x += "," if i > 0 x += cols[i] end end x += "\n" row = stream.fetch_row while(row != nil) begin _g11 = 0 _g2 = cols.length while(_g11 < _g2) i1 = _g11 _g11+=1 x += "," if i1 > 0 begin s = row[cols[i1]] x += s.to_s end end end x += "\n" row = stream.fetch_row end return x end end x1 = "" begin _g12 = 0 _g3 = tab.get_height while(_g12 < _g3) i2 = _g12 _g12+=1 begin _g31 = 0 _g21 = tab.get_width while(_g31 < _g21) j = _g31 _g31+=1 x1 += "," if j > 0 begin s1 = tab.get_cell(j,i2) x1 += s1.to_s end end end x1 += "\n" end end x1 end |
Instance Method Details
#clear ⇒ Object
70 71 72 |
# File 'lib/lib/coopy/simple_table.rb', line 70 def clear @data = {} end |
#clone ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/lib/coopy/simple_table.rb', line 213 def clone result = ::Coopy::SimpleTable.new(self.get_width,self.get_height) begin _g1 = 0 _g = self.get_height while(_g1 < _g) i = _g1 _g1+=1 begin _g3 = 0 _g2 = self.get_width while(_g3 < _g2) j = _g3 _g3+=1 result.set_cell(j,i,self.get_cell(j,i)) end end end end result. = .(result) if != nil result end |
#create ⇒ Object
236 237 238 |
# File 'lib/lib/coopy/simple_table.rb', line 236 def create ::Coopy::SimpleTable.new(self.get_width,self.get_height) end |
#get_cell(x, y) ⇒ Object
40 41 42 |
# File 'lib/lib/coopy/simple_table.rb', line 40 def get_cell(x,y) @data[x + y * @w] end |
#get_cell_view ⇒ Object
56 57 58 |
# File 'lib/lib/coopy/simple_table.rb', line 56 def get_cell_view ::Coopy::SimpleView.new end |
#get_data ⇒ Object
209 210 211 |
# File 'lib/lib/coopy/simple_table.rb', line 209 def get_data nil end |
#get_height ⇒ Object
36 37 38 |
# File 'lib/lib/coopy/simple_table.rb', line 36 def get_height @h end |
#get_meta ⇒ Object
244 245 246 |
# File 'lib/lib/coopy/simple_table.rb', line 244 def end |
#get_table ⇒ Object
23 24 25 |
# File 'lib/lib/coopy/simple_table.rb', line 23 def get_table self end |
#get_width ⇒ Object
32 33 34 |
# File 'lib/lib/coopy/simple_table.rb', line 32 def get_width @w end |
#height ⇒ Object
27 |
# File 'lib/lib/coopy/simple_table.rb', line 27 def height() get_height end |
#height=(__v) ⇒ Object
28 |
# File 'lib/lib/coopy/simple_table.rb', line 28 def height=(__v) @height = __v end |
#insert_or_delete_columns(fate, wfate) ⇒ Object
106 107 108 109 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 |
# File 'lib/lib/coopy/simple_table.rb', line 106 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 true end |
#insert_or_delete_rows(fate, hfate) ⇒ 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 99 100 101 102 103 104 |
# File 'lib/lib/coopy/simple_table.rb', line 74 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 true end |
#is_resizable ⇒ Object
60 61 62 |
# File 'lib/lib/coopy/simple_table.rb', line 60 def is_resizable true end |
#resize(w, h) ⇒ Object
64 65 66 67 68 |
# File 'lib/lib/coopy/simple_table.rb', line 64 def resize(w,h) @w = w @h = h true end |
#set_cell(x, y, c) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/lib/coopy/simple_table.rb', line 44 def set_cell(x,y,c) value = c begin value1 = value @data[x + y * @w] = value1 end end |
#set_meta(meta) ⇒ Object
240 241 242 |
# File 'lib/lib/coopy/simple_table.rb', line 240 def () = end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/lib/coopy/simple_table.rb', line 52 def to_s ::Coopy::SimpleTable.table_to_string(self) end |
#trim_blank ⇒ Object
138 139 140 141 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 |
# File 'lib/lib/coopy/simple_table.rb', line 138 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 true end |
#width ⇒ Object
29 |
# File 'lib/lib/coopy/simple_table.rb', line 29 def width() get_width end |
#width=(__v) ⇒ Object
30 |
# File 'lib/lib/coopy/simple_table.rb', line 30 def width=(__v) @width = __v end |