in progress
[jalview.git] / forester / ruby / evoruby / lib / evo / io / parser / basic_table_parser.rb
1 #
2 # = lib/evo/io/parser/basic_table_parser - BasicTableParser class
3 #
4 # Copyright::  Copyright (C) 2006-2007 Christian M. Zmasek
5 # License::    GNU Lesser General Public License (LGPL)
6 #
7 # $Id: basic_table_parser.rb,v 1.3 2007/09/28 03:12:10 cmzmasek Exp $
8 #
9 # last modified: 05/16/2007
10
11 module Evoruby
12
13     class BasicTableParser
14
15         START_OF_COMMENT_LINE_CHAR = "#"
16
17         # raises ArgumentError
18         def BasicTableParser.parse( path, column_delimiter )
19             Util.check_file_for_readability( path )
20             table = BasicTable.new
21             row = 0
22             File.open( path ) do | file |
23                 while line = file.gets
24                     if ( !Util.is_string_empty?( line ) &&
25                          !line.slice( 0, 1 ).eql?( START_OF_COMMENT_LINE_CHAR ) )
26                         values = line.split( column_delimiter )
27                         col = 0
28                         values.each { | value | 
29                             table.set_value( row, col, value.strip! )
30                             col += 1
31                         }
32                         row += 1
33                     end
34                 end
35             end
36             return table
37         end
38
39     end # class BasicTableParser
40
41 end # module Evoruby