Module: BioTable::LineParser

Defined in:
lib/bio-table/parser.rb

Class Method Summary collapse

Class Method Details

.parse(line, in_format, split_on) ⇒ Object

Converts a string into an array of string fields



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bio-table/parser.rb', line 8

def LineParser::parse(line, in_format, split_on)
  if in_format == :csv
    $stderr.print "WARNING: this looks like a tab delimited file to me!\n" if line =~ /\t/
    CSV.parse_line(line)
  elsif in_format == :split
    line.split(split_on).map { |field| 
      fld = field.strip
      fld = nil if fld == "NA"
      fld
    }
  elsif in_format == :regex
    line.split(/#{split_on}/).map { |field| 
      fld = field.strip
      fld = nil if fld == "NA"
      fld
    }
  else
    $stderr.print "WARNING: this looks like a tab delimited file to me!\n" if line =~ /,"/
    line.split("\t").map { |field| 
      fld = field.strip
      fld = nil if fld == "NA"
      fld
    }
  end
end