Class: Ms::DataExplorer::Format::Ascii

Inherits:
Spectrum
  • Object
show all
Defined in:
lib/ms/data_explorer/format/ascii.rb

Class Method Summary collapse

Class Method Details

.parse(str) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ms/data_explorer/format/ascii.rb', line 12

def parse(str)
  headers = {}
  data = []
  
  str.split(/\r?\n/).each do |line|
    line = line.strip
    next if line.empty?
    
    key, value = line.split(/\s+/, 2)
    if key =~ /^\d/
      data << [key.to_f, value.to_f]
    else
      headers[key] = value
    end
  end
  
  new(Data.new(data, :transposed), headers)
end