Class: ODDB::AnalysisParse::AnalysisHpricot

Inherits:
Object
  • Object
show all
Defined in:
ext/analysisparse/src/analysis_hpricot.rb

Constant Summary

URL_BASE =
"http://www.dacapo.ch/analysen/"

Instance Method Summary (collapse)

Constructor Details

- (AnalysisHpricot) initialize

A new instance of AnalysisHpricot



13
14
15
# File 'ext/analysisparse/src/analysis_hpricot.rb', line 13

def initialize
  @iconv = Iconv.new('UTF-8', 'ISO-8859-1')
end

Instance Method Details

- (Object) dacapo_infos(&block)



16
17
18
19
20
21
# File 'ext/analysisparse/src/analysis_hpricot.rb', line 16

def dacapo_infos(&block)
  ("A".."Z").each { |letter|
    doc = Hpricot(open(URL_BASE + "view.php?match=" + letter + "&lab_id=0"))
    fetch_position_hrefs(doc, &block)
  }
end

- (Object) fetch_additional_info(html)



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'ext/analysisparse/src/analysis_hpricot.rb', line 30

def fetch_additional_info(html)
  result = {}
  doc = Hpricot(html)
  elements = doc.search("//tr[@align='left']")
  elements = (elements/"//td[@colspan='2']")
  elements.each_with_index { |elem, index|
    case (elem/"strong").inner_html
    when "Beschreibung"
      val = format_string(elements[index+1].inner_html)
      result.store(:info_description, val)
    when "Interpretation"
      val = format_string(elements[index+1].inner_html)
      result.store(:info_interpretation, val)
    when "Indikation"
      val = format_string(elements[index+1].inner_html)
      result.store(:info_indication, val)
    when "Aussagekraft (Bewertung)"
      val = format_string(elements[index+1].inner_html)
      result.store(:info_significance, val)
    when "Entnahmematerial"
      val = format_string(elements[index+1].inner_html)
        result.store(:info_ext_material, val)
    when "Entnahmebedingungen"
      val = format_string(elements[index+1].inner_html)
      result.store(:info_ext_condition, val)
    when "Lagerungsbedingungen"
      val = format_string(elements[index+1].inner_html)
      result.store(:info_storage_condition, val)
    when "Lagerunsgdauer"
      val = format_string(elements[index+1].inner_html)
      result.store(:info_storage_time, val)
    end
  }
  result
end

- (Object) fetch_position_hrefs(doc, &block)



22
23
24
25
26
27
28
29
# File 'ext/analysisparse/src/analysis_hpricot.rb', line 22

def fetch_position_hrefs(doc, &block) 
  (doc/"a").each { |pos| 
    code = pos.inner_html
    url = URL_BASE + pos.attributes['href']
    info = fetch_additional_info(open(url))
    block.call(code, info)
  }
end

- (Object) format_string(text)



65
66
67
68
69
70
# File 'ext/analysisparse/src/analysis_hpricot.rb', line 65

def format_string(text)
  text = text.gsub(/\s+/u, ' ')
  @iconv.iconv text
rescue Iconv::IllegalSequence
  text
end