Class: ODDB::MedData::ResultWriter

Inherits:
NullWriter show all
Defined in:
ext/meddata/src/meddparser.rb

Constant Summary

DG_PATTERNS =
{
  :partner => /DgMedwinPartner/u,
  :product => /DgMedrefProduct/u,
  :refdata => /DgMedrefProduct/u,
}

Instance Method Summary (collapse)

Methods inherited from NullWriter

#new_fonthandler, #send_image, #send_meta

Constructor Details

- (ResultWriter) initialize(search_type = :partner)

A new instance of ResultWriter



25
26
27
28
29
# File 'ext/meddata/src/meddparser.rb', line 25

def initialize(search_type=:partner)
  @dg_pattern = DG_PATTERNS[search_type]
  @tablehandlers = []
  @linkhandlers = []
end

Instance Method Details

- (Object) extract_data



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'ext/meddata/src/meddparser.rb', line 30

def extract_data
  data = {}
  @tablehandlers.each { |handler|
    unless(handler.nil?)
      if(handler.attributes.any? { |key, val|
        @dg_pattern.match(val)
      })
        handler.each_row { |row|
        unless(row.children(0).empty?)
          arr = row.children(0).first.attributes['href'].split("$")
          data.store(arr[1], [row.cdata(1), row.cdata(2), row.cdata(3)])
        end
        }
      end
    end
  }
  data
end

- (Object) new_linkhandler(handler)



48
49
50
51
52
# File 'ext/meddata/src/meddparser.rb', line 48

def new_linkhandler(handler)
  unless(@current_tablehandler.nil?)
    @current_tablehandler.add_child(handler)
  end
end

- (Object) new_tablehandler(handler)



53
54
55
56
# File 'ext/meddata/src/meddparser.rb', line 53

def new_tablehandler(handler)
  @current_tablehandler = handler
  @tablehandlers.push(handler)
end

- (Object) send_flowing_data(data)



57
58
59
60
61
# File 'ext/meddata/src/meddparser.rb', line 57

def send_flowing_data(data) 
  unless(@current_tablehandler.nil?)
    @current_tablehandler.send_cdata(data)
  end
end