1 # = lib/evo/table/basic_table.rb - BasicTable class
3 # Copyright:: Copyright (C) 2006-2007 Christian M. Zmasek
4 # License:: GNU Lesser General Public License (LGPL)'s
6 # $Id: basic_table.rb,v 1.3 2007/09/28 03:12:10 cmzmasek Exp $
8 # last modified: 05/16/2007
10 #require 'lib/evo/util/constants'
22 # raises ArgumentError
23 def set_value( row, col, value )
24 if ( ( row < 0 ) || ( col < 0 ) )
25 raise( ArgumentError, "attempt to use negative values for row or column" )
27 if ( row > get_max_row() )
30 if ( col > get_max_col() )
34 if ( @rows.has_key?( row ) )
35 row_map = @rows[ row ]
38 @rows[ row ] = row_map
40 row_map[ col ] = value
43 # raises ArgumentError
44 def get_value_as_string( row, col )
45 return ( get_value( row, col ) ).to_s
48 # raises ArgumentError
49 def get_value( row, col )
50 if ( ( row > get_max_row() ) || ( row < 0 ) )
51 raise( ArgumentError, "value for row (" + row.to_s +
52 ") is out of range [max row: " + get_max_row().to_s + "]" )
53 elsif ( ( col > get_max_col() ) || ( row < 0 ) )
54 raise( ArgumentError, "value for column (" + col.to_s +
55 ") is out of range [max column: " + get_max_col().to_s + "]" )
57 row_map = @rows[ row ]
58 if ( ( row_map == nil ) || ( row_map.length < 1 ) )
72 # raises ArgumentError
73 def get_columns_as_map( key_col, value_col )
75 for row in 0 .. get_max_row
76 key = get_value( row, key_col )
77 value = get_value( row, value_col )
78 if ( ( key != nil ) && ( value != nil ) )
79 if ( map.has_key?( key ) )
80 raise( ArgumentError, "attempt to use non-unique table value as key [" +
91 for row in 0 .. get_max_row
92 for col in 0 .. get_max_col
93 str << col.to_s << " "
95 str << LEvoruby::Constants::LINE_DELIMITER
96 for col in 0 .. get_max_col
97 str << row.to_s << ": "
98 str << get_value( row, col ) << " "
100 str << Evoruby::Constants::LINE_DELIMITER
112 def set_max_col( max_col )
116 def set_max_row( max_row )
120 end # class BasicTable