class Coopy::TableView

Public Class Methods

new(data) click to toggle source
# 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

Public Instance Methods

clear() click to toggle source
# File lib/lib/coopy/table_view.rb, line 54
def clear
  @data.clear
  @width = 0
  @height = 0
end
clone() click to toggle source
# 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() click to toggle source
# File lib/lib/coopy/table_view.rb, line 140
def create
  TableView.new([])
end
get_cell(x,y) click to toggle source
# File lib/lib/coopy/table_view.rb, line 14
def get_cell(x,y)
  @data[y][x]
end
get_cell_view() click to toggle source
# File lib/lib/coopy/table_view.rb, line 26
def get_cell_view
  ::Coopy::SimpleView.new
end
get_data() click to toggle source
# File lib/lib/coopy/table_view.rb, line 64
def get_data
  return @data
end
get_height() click to toggle source
# File lib/lib/coopy/table_view.rb, line 12
def get_height() @height end
get_meta() click to toggle source
# File lib/lib/coopy/table_view.rb, line 144
def get_meta
  nil
end
get_width() click to toggle source
# File lib/lib/coopy/table_view.rb, line 10
def get_width() @width end
insert_or_delete_columns(fate,wfate) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/lib/coopy/table_view.rb, line 30
def is_resizable
  true
end
is_similar(alt) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/lib/coopy/table_view.rb, line 18
def set_cell(x,y,c)
  @data[y][x] = c
end
to_s() click to toggle source
# File lib/lib/coopy/table_view.rb, line 22
def to_s
  ::Coopy::SimpleTable::table_to_string(self)
end
trim_blank() click to toggle source
# File lib/lib/coopy/table_view.rb, line 60
def trim_blank
  false
end