class Coopy::SimpleTable

Attributes

data[RW]

protected - in ruby this doesn't play well with static/inline methods

h[RW]
meta[RW]
w[RW]

Public Class Methods

new(w,h) click to toggle source
# File lib/lib/coopy/simple_table.rb, line 7
def initialize(w,h)
  @data = {}
  @w = w
  @h = h
  @meta = nil
end
table_is_similar(tab1,tab2) click to toggle source
# 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) click to toggle source
# File lib/lib/coopy/simple_table.rb, line 248
def SimpleTable.table_to_string(tab)
  meta = tab.get_meta
  if meta != nil 
    stream = meta.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

Public Instance Methods

clear() click to toggle source
# File lib/lib/coopy/simple_table.rb, line 70
def clear 
  @data = {}
end
clone() click to toggle source
# 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.meta = @meta.clone_meta(result) if @meta != nil
  result
end
create() click to toggle source
# 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) click to toggle source
# File lib/lib/coopy/simple_table.rb, line 40
def get_cell(x,y)
  @data[x + y * @w]
end
get_cell_view() click to toggle source
# File lib/lib/coopy/simple_table.rb, line 56
def get_cell_view 
  ::Coopy::SimpleView.new
end
get_data() click to toggle source
# File lib/lib/coopy/simple_table.rb, line 209
def get_data 
  nil
end
get_height() click to toggle source
# File lib/lib/coopy/simple_table.rb, line 36
def get_height 
  @h
end
get_meta() click to toggle source
# File lib/lib/coopy/simple_table.rb, line 244
def get_meta 
  @meta
end
get_table() click to toggle source
# File lib/lib/coopy/simple_table.rb, line 23
def get_table 
  self
end
get_width() click to toggle source
# File lib/lib/coopy/simple_table.rb, line 32
def get_width 
  @w
end
height() click to toggle source
# File lib/lib/coopy/simple_table.rb, line 27
def height() get_height end
height=(__v) click to toggle source
# File lib/lib/coopy/simple_table.rb, line 28
def height=(__v) @height = __v end
insert_or_delete_columns(fate,wfate) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/lib/coopy/simple_table.rb, line 60
def is_resizable 
  true
end
resize(w,h) click to toggle source
# File lib/lib/coopy/simple_table.rb, line 64
def resize(w,h)
  @w = w
  @h = h
  true
end
set_cell(x,y,c) click to toggle source
# 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) click to toggle source
# File lib/lib/coopy/simple_table.rb, line 240
def set_meta(meta)
  @meta = meta
end
to_s() click to toggle source
# File lib/lib/coopy/simple_table.rb, line 52
def to_s 
  ::Coopy::SimpleTable.table_to_string(self)
end
trim_blank() click to toggle source
# 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() click to toggle source
# File lib/lib/coopy/simple_table.rb, line 29
def width() get_width end
width=(__v) click to toggle source
# File lib/lib/coopy/simple_table.rb, line 30
def width=(__v) @width = __v end