Class: Oddb2xml::SwissmedicInfoExtractor
- Defined in:
- lib/oddb2xml/extractor.rb
Instance Attribute Summary
Attributes inherited from Extractor
Instance Method Summary collapse
Methods inherited from Extractor
Constructor Details
This class inherits a constructor from Oddb2xml::Extractor
Instance Method Details
#to_hash ⇒ Object
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/oddb2xml/extractor.rb', line 331 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 lang =~ /de|fr/ item = {} item[:name] = (name = pac.title) ? name : '' item[:owner] = (ownr = pac.authHolder) ? ownr : '' if content = /cdata/.match(pac.content) html = Nokogiri::HTML(content.to_s) # all HTML contents without MonTitle and ownerCompany item[:paragraph] = "<title><p>#{item[:name]}</p></title>" + ((paragraph = html.xpath("///div[@class='paragraph']")) ? paragraph.to_s : '') if text = html.xpath("///div[@id='Section7750']/p").text # 1 ~ 3 swissmedic number if text =~ /(\d{5})[,\s]*(\d{5})?|(\d{5})[,\s]*(\d{5})?[,\s]*(\d{5})?/ [$1, $2, $3].compact.each do |n| # plural item[:monid] = n data[lang] << item end end end end end data end |