Class: ODDB::DocData::DoctorWriter

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

Constant Summary

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)

Methods inherited from NullWriter

#new_fonthandler, #new_linkhandler, #send_image, #send_meta

Constructor Details

- (DoctorWriter) initialize

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

- (Object) collected_values (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

- (Object) extract_data



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

- (Object) get_plz_city(array)



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

- (Object) handle_array_data(ary, value, type)



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

- (Object) handle_data(key, value, type)



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

- (Object) handle_scalar_data(key, value)



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

- (Object) new_tablehandler(handler)



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

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

- (Object) send_flowing_data(data)



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

- (Object) send_line_break



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

- (Object) translate_key(string)



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

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