Class: ODDB::Swissreg::DetailWriter
- Defined in:
- ext/swissreg/src/writer.rb
Instance Attribute Summary collapse
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Instance Method Summary collapse
- #date(str) ⇒ Object
- #extract_data ⇒ Object
-
#initialize(*args) ⇒ DetailWriter
constructor
A new instance of DetailWriter.
- #new_linkhandler(link) ⇒ Object
- #new_tablehandler(table) ⇒ Object
- #send_flowing_data(data) ⇒ Object
- #send_line_break ⇒ Object
Constructor Details
#initialize(*args) ⇒ DetailWriter
Returns 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
#tables ⇒ Object (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
#date(str) ⇒ Object
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 |
#extract_data ⇒ Object
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 |
#new_linkhandler(link) ⇒ Object
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 |
#new_tablehandler(table) ⇒ Object
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 |
#send_flowing_data(data) ⇒ Object
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 |
#send_line_break ⇒ Object
75 76 77 78 79 |
# File 'ext/swissreg/src/writer.rb', line 75 def send_line_break if(@table) @table.next_line end end |