Class: ODDB::Swissreg::DetailWriter

Inherits:
NullWriter show all
Defined in:
ext/swissreg/src/writer.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NullWriter

#new_fonthandler, #send_image, #send_meta

Constructor Details

- (DetailWriter) initialize(*args)

A new instance of DetailWriter



11
12
13
14
# File 'ext/swissreg/src/writer.rb', line 11

def initialize(*args)
  super
  @tables = []
end

Instance Attribute Details

- (Object) tables (readonly)

Returns the value of attribute tables



10
11
12
# File 'ext/swissreg/src/writer.rb', line 10

def tables
  @tables
end

Instance Method Details

- (Object) date(str)



15
16
17
# File 'ext/swissreg/src/writer.rb', line 15

def date(str)
  Date.new(*(str.split('.').reverse.collect { |num| num.to_i }))
end

- (Object) extract_data



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'ext/swissreg/src/writer.rb', line 18

def extract_data
  data = {}
  @tables.at(1).each_row { |row|
    case(row.cdata(0))
    when /genehmigung/iu
      data[:iksnrs] = [row.cdata(1)].flatten.collect { |str|
        if(match = /(?:iks|oicm|swissmedic),?\s+(\d{5})\b/iu.match(str))
          match[1]
        elsif(match = /bag,?\s+(\d{3,5})\b/iu.match(str))
          sprintf("%05i", match[1])
        end
      }.compact
    when /schutzdauerbeginn/iu
      data.store(:protection_date, date(row.cdata(1)))
    when /l.{1,2}schdatum/iu
      data.store(:deletion_date, date(row.cdata(1)))
    when /anmeldedatum/iu
      data.store(:registration_date, date(row.cdata(1)))
    when /erteilungsdatum/iu
      data.store(:issue_date, date(row.cdata(1)))
    when /esz-nr/iu
      data.store(:certificate_number, row.cdata(1).strip)
    when /grundpatent-nr/iu
      data.store(:base_patent, row.cdata(1))
    when /maximale laufzeit/iu
      data.store(:expiry_date, date(row.cdata(1)))
    when /publikationsdatum/iu
      data.store(:publication_date, date(row.cdata(1)))
    when /schutzbeginn grundpatent/iu
      data.store(:base_patent_date, date(row.cdata(1)))
    end
  }
  data
end

- (Object) new_linkhandler(link)



52
53
54
55
56
57
58
59
# File 'ext/swissreg/src/writer.rb', line 52

def new_linkhandler(link)
  if(link)
    @link = link
  elsif(@link && @table)
    @table.add_child(@link)
    @link = nil
  end
end

- (Object) new_tablehandler(table)



60
61
62
63
64
65
66
67
# File 'ext/swissreg/src/writer.rb', line 60

def new_tablehandler(table)
  if(table)
    @tables.push(table)
    @table = table
  else
    @table = nil
  end
end

- (Object) send_flowing_data(data)



68
69
70
71
72
73
74
# File 'ext/swissreg/src/writer.rb', line 68

def send_flowing_data(data)
  if(@table)
    @table.send_cdata(data)
  elsif(@link)
    @link.send_adata(data)
  end
end

- (Object) send_line_break



75
76
77
78
79
# File 'ext/swissreg/src/writer.rb', line 75

def send_line_break
  if(@table)
    @table.next_line
  end
end