Class: ODDB::MedData::ResultWriter

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

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(search_type = :partner) ⇒ ResultWriter

Returns 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

#extract_dataObject



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

#new_linkhandler(handler) ⇒ Object



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

#new_tablehandler(handler) ⇒ Object



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

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

#send_flowing_data(data) ⇒ Object



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