Class: Oddb2xml::SwissmedicInfoExtractor

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

Instance Attribute Summary

Attributes inherited from Extractor

#xml

Instance Method Summary collapse

Methods inherited from Extractor

#initialize

Constructor Details

This class inherits a constructor from Oddb2xml::Extractor

Instance Method Details

#to_hashObject



390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# File 'lib/oddb2xml/extractor.rb', line 390

def to_hash
  data = Hash.new { |h, k| h[k] = [] }
  return data unless @xml.size > 0
  result = MedicalInformationsContent.parse(@xml.sub(STRIP_FOR_SAX_MACHINE, ""), lazy: true)
  result.medicalInformation.each do |pac|
    lang = pac.lang.to_s
    next unless /de|fr/.match?(lang)
    item = {}
    item[:refdata] = true
    item[:data_origin] = "swissmedic_info"
    item[:name] = (name = pac.title) ? name : ""
    item[:owner] = (ownr = pac.authHolder) ? ownr : ""
    item[:style] = Nokogiri::HTML.fragment(pac.style).to_html(encoding: "UTF-8")
    html = Nokogiri::HTML.fragment(pac.content.force_encoding("UTF-8"))
    item[:paragraph] = html
    numbers = /(\d{5})[,\s]*(\d{5})?|(\d{5})[,\s]*(\d{5})?[,\s]*(\d{5})?/.match(html)
    if numbers
      [$1, $2, $3].compact.each do |n| # plural
        item[:monid] = n
        data[lang] << item
      end
    end
  end
  data
end