Class: ODDB::DocData::DoctorWriter

Inherits:
NullWriter
  • Object
show all
Defined in:
ext/docdata/src/docparser.rb

Constant Summary collapse

TRANSLATE_KEYS =
{
	'Telefon:'	=>	:fon,
	'Telefax:'	=>	:fax,	
	'Email:'		=>	:email,
	'Adresse:'	=>	:addresses,
	'PLZ:'			=>	:plz,
	'Ort:'			=>	:city,
	'Anrede:'		=>	:salutation,
	'Titel:'		=>	:title,
	'Name:'			=>	:name,
	'Vorname:'	=>	:firstname,
	'Email:'		=>	:email,
	'EAN:'			=>	:ean13,
	'Praxis'		=>	:praxis,
	'Staatsexamensjahr:'		=>	:exam,
	'Korrespondenzsprache:'	=>	:language,
	'Facharzttitel:'				=>	:specialities,
	'Fähigkeitsausweis:'		=>	:abilities,
	'Fertigkeitsausweis:'		=>	:skills,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDoctorWriter

Returns a new instance of DoctorWriter.



41
42
43
44
45
# File 'ext/docdata/src/docparser.rb', line 41

def initialize
	@tablehandlers = []
	@collected_values = {}
	@type = nil
end

Instance Attribute Details

#collected_valuesObject (readonly)

Returns the value of attribute collected_values.



20
21
22
# File 'ext/docdata/src/docparser.rb', line 20

def collected_values
  @collected_values
end

Instance Method Details

#extract_dataObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'ext/docdata/src/docparser.rb', line 49

def extract_data
	type = nil
	if(handler = @tablehandlers.at(2))
		handler.each_row { |row|
			if(row.cdata(0))
				unless(row.cdata(0).is_a?(Array))
					if(row.cdata(0).match(/Praxis-Adresse/u))
						type = :praxis
					elsif(row.cdata(0).match(/Adresse Arbeitsort/u))
						type = :work
					end	
				end
			end
			handle_data(row.cdata(0), row.cdata(1), type)
			handle_data(row.cdata(2), row.cdata(3), type)
			@current_address = nil
		}
	end
end

#get_plz_city(array) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'ext/docdata/src/docparser.rb', line 68

def get_plz_city(array)
	arr = []
	array.each { |str|
		if(str.match(/[\d]{4}/u))
			arr = str.split(" ")
		end
	}
	arr
end

#handle_array_data(ary, value, type) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'ext/docdata/src/docparser.rb', line 84

def handle_array_data(ary, value, type)
	if(ary.first == "Adresse:")
		plz_city = get_plz_city(value)
		addr_hash = {
			:plz	=>	plz_city.first,
			:city	=>	plz_city.last,
			:lines	=>	value,
			:type		=>	type,
		}
		handle_scalar_data('Adresse:', addr_hash)
		@current_address = addr_hash
	else
		ary.each_with_index { |str, idx|
			val = (value.is_a? Array) ? 
				value.at(idx) : value
			handle_scalar_data(str, val)
		}
	end
end

#handle_data(key, value, type) ⇒ Object



77
78
79
80
81
82
83
# File 'ext/docdata/src/docparser.rb', line 77

def handle_data(key, value, type)
	if(key.is_a?(Array))
		handle_array_data(key, value, type)
	else
		handle_scalar_data(key, value)
	end
end

#handle_scalar_data(key, value) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'ext/docdata/src/docparser.rb', line 103

def handle_scalar_data(key, value)
	string = key.to_s.delete("\302\240").strip
	if(key = translate_key(string))
		if(@current_address)
			@current_address.store(key, value)
		elsif(@collected_values.include?(key))
			values = @collected_values[key]
			unless values.is_a?(Array)	
				@collected_values[key] = [values]
			end
			@collected_values[key].push(value)
		else
			@collected_values.store(key, value)
		end
	end
end

#new_tablehandler(handler) ⇒ Object



119
120
121
122
# File 'ext/docdata/src/docparser.rb', line 119

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

#send_flowing_data(data) ⇒ Object



123
124
125
126
127
# File 'ext/docdata/src/docparser.rb', line 123

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

#send_line_breakObject



128
129
130
131
132
# File 'ext/docdata/src/docparser.rb', line 128

def send_line_break
	unless(@current_tablehandler.nil?)
		@current_tablehandler.next_line
	end
end

#translate_key(string) ⇒ Object



46
47
48
# File 'ext/docdata/src/docparser.rb', line 46

def translate_key(string)
	TRANSLATE_KEYS[string.strip]
end