Class: Coopy::TableView
- Inherits:
-
Table
- Object
- Table
- Coopy::TableView
show all
- Defined in:
- lib/lib/coopy/table_view.rb
Instance Method Summary
collapse
Methods inherited from Table
#getCell, #getCellView, #getData, #getMeta, #insertOrDeleteColumns, #insertOrDeleteRows, #isResizable, #setCell, #trimBlank
Constructor Details
#initialize(data) ⇒ TableView
Returns a new instance of TableView.
3
4
5
6
7
8
|
# File 'lib/lib/coopy/table_view.rb', line 3
def initialize(data)
@data = data
@height = data.length
@width = 0
@width = data[0].length if @height>0
end
|
Instance Method Details
#clear ⇒ Object
54
55
56
57
58
|
# File 'lib/lib/coopy/table_view.rb', line 54
def clear
@data.clear
@width = 0
@height = 0
end
|
#clone ⇒ Object
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/lib/coopy/table_view.rb', line 129
def clone
result = TableView.new([])
result.resize(@width,@height)
@width.times do |c|
@height.times do |r|
result.set_cell(c,r,self.get_cell(c,r))
end
end
result
end
|
#create ⇒ Object
140
141
142
|
# File 'lib/lib/coopy/table_view.rb', line 140
def create
TableView.new([])
end
|
#get_cell(x, y) ⇒ Object
14
15
16
|
# File 'lib/lib/coopy/table_view.rb', line 14
def get_cell(x,y)
@data[y][x]
end
|
#get_cell_view ⇒ Object
26
27
28
|
# File 'lib/lib/coopy/table_view.rb', line 26
def get_cell_view
::Coopy::SimpleView.new
end
|
#get_data ⇒ Object
64
65
66
|
# File 'lib/lib/coopy/table_view.rb', line 64
def get_data
return @data
end
|
#get_height ⇒ Object
12
|
# File 'lib/lib/coopy/table_view.rb', line 12
def get_height() @height end
|
144
145
146
|
# File 'lib/lib/coopy/table_view.rb', line 144
def get_meta
nil
end
|
#get_width ⇒ Object
10
|
# File 'lib/lib/coopy/table_view.rb', line 10
def get_width() @width end
|
#insert_or_delete_columns(fate, wfate) ⇒ Object
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
109
110
|
# File 'lib/lib/coopy/table_view.rb', line 82
def insert_or_delete_columns(fate,wfate)
if wfate==@width and wfate==fate.length
eq = true
wfate.times do |i|
if fate[i]!=i
eq = false
break
end
end
return true if eq
end
@height.times do |i|
row = @data[i]
nrow = []
@width.times do |j|
next if fate[j]==-1
nrow[fate[j]] = row[j]
end
while nrow.length<wfate
nrow << nil
end
@data[i] = nrow
end
@width = wfate
if @width == 0
@height = 0
end
true
end
|
#insert_or_delete_rows(fate, hfate) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/lib/coopy/table_view.rb', line 68
def insert_or_delete_rows(fate,hfate)
ndata = []
fate.length.times do |i|
j = fate[i];
ndata[j] = @data[i] if j!=-1
end
@data.clear
ndata.length.times do |i|
@data[i] = ndata[i]
end
self.resize(@width,hfate)
true
end
|
#is_resizable ⇒ Object
30
31
32
|
# File 'lib/lib/coopy/table_view.rb', line 30
def is_resizable
true
end
|
#is_similar(alt) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/lib/coopy/table_view.rb', line 112
def is_similar(alt)
return false if alt.width!=@width
return false if alt.height!=@height
@width.times do |c|
@height.times do |r|
v1 = "" + self.get_cell(c,r)
v2 = "" + alt.get_cell(c,r)
if (v1!=v2)
puts("MISMATCH "+ v1 + " " + v2);
return false
end
end
end
true
end
|
#resize(w, h) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/lib/coopy/table_view.rb', line 34
def resize(w,h)
@width = w
@height = h
@data.length.times do |i|
row = @data[i]
row = @data[i] = [] if row.nil?
while row.length<w
row << nil
end
end
while @data.length<h
row = []
w.times do |i|
row << nil
end
@data << row
end
true
end
|
#set_cell(x, y, c) ⇒ Object
18
19
20
|
# File 'lib/lib/coopy/table_view.rb', line 18
def set_cell(x,y,c)
@data[y][x] = c
end
|
#to_s ⇒ Object
22
23
24
|
# File 'lib/lib/coopy/table_view.rb', line 22
def to_s
::Coopy::SimpleTable::table_to_string(self)
end
|
#trim_blank ⇒ Object
60
61
62
|
# File 'lib/lib/coopy/table_view.rb', line 60
def trim_blank
false
end
|