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

Constructor Details

#initialize(str) ⇒ EphaExtractor

Returns a new instance of EphaExtractor.



414
415
416
417
# File 'lib/oddb2xml/extractor.rb', line 414

def initialize(str)
  Oddb2xml.log("EphaExtractor #{str.size} bytes")
  @io = StringIO.new(str)
end

Instance Method Details

#to_arryObject



419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'lib/oddb2xml/extractor.rb', line 419

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[:data_origin] = "epha"
      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