Class: Oddb2xml::EphaExtractor

Inherits:
Extractor show all
Defined in:
lib/oddb2xml/extractor.rb

Instance Attribute Summary

Attributes inherited from Extractor

#xml

Instance Method Summary collapse

Methods inherited from Extractor

#correct_code

Constructor Details

#initialize(str) ⇒ EphaExtractor

Returns a new instance of EphaExtractor.



377
378
379
# File 'lib/oddb2xml/extractor.rb', line 377

def initialize(str)
  @io = StringIO.new(str)
end

Instance Method Details

#to_arryObject



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/oddb2xml/extractor.rb', line 380

def to_arry
  data = []
  ixno = 0
  inhalt = @io.read
  inhalt.split("\n").each do |line|
    ixno += 1
    next if /ATC1.*Name1.*ATC2.*Name2/.match(line)
    #line = '"'+line unless /^"/.match(line)
    begin
      row = CSV.parse_line(line.gsub('""','"'))
      action = {}
      next unless row.size > 8
      action[:ixno]      = ixno
      action[:title]     = row[4]
      action[:atc1]      = row[0]
      action[:atc2]      = row[2]
      action[:mechanism] = row[5]
      action[:effect]    = row[6]
      action[:measures]  = row[7]
      action[:grad]      = row[8]
      data << action
    rescue CSV::MalformedCSVError
      puts "CSV::MalformedCSVError in line #{ixno}: #{line}"
    end
  end
  data
end