Class: ODDB::FiParse::FachinfoDocWriter

Inherits:
FachinfoWriter show all
Defined in:
ext/fiparse/src/fachinfo_doc.rb,
ext/fiparse/test/test_fachinfo_doc_parser.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from FachinfoWriterMethods

#to_fachinfo

Methods inherited from Writer

#initialize, #new_alignment, #next_chapter, #send_hor_rule, #send_line_break, #send_literal_data

Methods inherited from NullWriter

#new_fonthandler, #new_linkhandler, #new_tablehandler, #send_image, #send_meta

Constructor Details

This class inherits a constructor from ODDB::FiParse::Writer

Instance Attribute Details

- (Object) chapters (readonly)

Returns the value of attribute chapters



20
21
22
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 20

def chapters
  @chapters
end

- (Object) company (readonly)

Returns the value of attribute company



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def company
  @company
end

- (Object) composition (readonly)

Returns the value of attribute composition



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def composition
  @composition
end

- (Object) contra_indications (readonly)

Returns the value of attribute contra_indications



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def contra_indications
  @contra_indications
end

- (Object) cutoff_fontsize

Returns the value of attribute cutoff_fontsize



11
12
13
# File 'ext/fiparse/src/fachinfo_doc.rb', line 11

def cutoff_fontsize
  @cutoff_fontsize
end

- (Object) date (readonly)

Returns the value of attribute date



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def date
  @date
end

- (Object) driving_ability (readonly)

Returns the value of attribute driving_ability



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def driving_ability
  @driving_ability
end

- (Object) effects (readonly)

Returns the value of attribute effects



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def effects
  @effects
end

- (Object) galenic_form (readonly)

Returns the value of attribute galenic_form



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def galenic_form
  @galenic_form
end

- (Object) iksnrs (readonly)

Returns the value of attribute iksnrs



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def iksnrs
  @iksnrs
end

- (Object) indications (readonly)

Returns the value of attribute indications



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def indications
  @indications
end

- (Object) interactions (readonly)

Returns the value of attribute interactions



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def interactions
  @interactions
end

- (Object) kinetic (readonly)

Returns the value of attribute kinetic



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def kinetic
  @kinetic
end

- (Object) name (readonly)

Returns the value of attribute name



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def name
  @name
end

- (Object) other_advice (readonly)

Returns the value of attribute other_advice



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def other_advice
  @other_advice
end

- (Object) overdose (readonly)

Returns the value of attribute overdose



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def overdose
  @overdose
end

- (Object) packages (readonly)

Returns the value of attribute packages



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def packages
  @packages
end

- (Object) preclinic (readonly)

Returns the value of attribute preclinic



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def preclinic
  @preclinic
end

- (Object) pregnancy (readonly)

Returns the value of attribute pregnancy



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def pregnancy
  @pregnancy
end

- (Object) registration_owner (readonly)

Returns the value of attribute registration_owner



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def registration_owner
  @registration_owner
end

- (Object) restrictions (readonly)

Returns the value of attribute restrictions



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def restrictions
  @restrictions
end

- (Object) unwanted_effects (readonly)

Returns the value of attribute unwanted_effects



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def unwanted_effects
  @unwanted_effects
end

- (Object) usage (readonly)

Returns the value of attribute usage



14
15
16
# File 'ext/fiparse/test/test_fachinfo_doc_parser.rb', line 14

def usage
  @usage
end

Instance Method Details

- (Object) cell_end



29
30
31
# File 'ext/fiparse/src/fachinfo_doc.rb', line 29

def cell_end
  #@target = nil
end

- (Object) cell_start



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'ext/fiparse/src/fachinfo_doc.rb', line 12

def cell_start
  idx = @table.current_row.size
  @target = @table.next_cell!
  if(desc = @row.cell_descriptors[idx])
    if(desc.first_merged?)
      @horizontal_master = @target
    elsif(desc.merged?)
      @horizontal_master.col_span += 1
    end
    if(desc.vertical_restart?)
      @vertical_master = @target
    elsif(desc.vertical_merged?)
      @vertical_master.row_span += 1
    end
  end
  @target
end

- (Boolean) check_exception?(text)

Returns:

  • (Boolean)


153
154
155
156
157
158
159
160
# File 'ext/fiparse/src/fachinfo_doc.rb', line 153

def check_exception?(text)
  case text.strip
  when /Composition/u, /Zusammensetzung/u
    false
  else
    true
  end
end

- (Boolean) complete?

Returns:

  • (Boolean)


32
33
34
# File 'ext/fiparse/src/fachinfo_doc.rb', line 32

def complete?
  @date && !@date.sections.empty?
end

- (Object) fix_colspans



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'ext/fiparse/src/fachinfo_doc.rb', line 35

def fix_colspans
  all_boundaries = @boundaries.flatten.uniq.compact
  @table.rows.each_with_index { |row, y_idx|
    row.each_with_index { |cell, x_idx|
      left, right = @boundaries[y_idx][x_idx, 2]
      between = all_boundaries.select { |bound|
        bound >= left && ((right.nil?) || bound < right)
      }.size
      if(cell.col_span < between)
        cell.col_span = between
      end
    }
  }
end

- (Object) named_chapter

- (Object) named_chapters

- (Object) new_font(char_props, text = nil)



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'ext/fiparse/src/fachinfo_doc.rb', line 49

def new_font(char_props, text=nil)
  if(@chapter_flag)
    @chapter_flag = nil
    if(@chapter == @switch)
      # switch between old and new (2001) FI-Schema
      set_templates(@chapter)
    elsif([@company, @galenic_form].include?(@chapter) \
      && /Zusammensetzung|Composition|Principes\s*actifs/iu.match(@chapter.heading))
      if(@chapter == @company)
        @company = nil
      end
      @composition = @chapter 
      @amzv = Text::Chapter.new
      @templates = named_chapters [
        :galenic_form, :indications, :usage, 
        :contra_indications, :restrictions,
        :interactions, :pregnancy, :driving_ability,
        :unwanted_effects, :overdose, :effects, :switch,
      ]
    end
  end
  if(!@row && char_props.fontsize >= @cutoff_fontsize && @name.empty?)
    set_target(@name)
  #elsif(char_props.italic? && char_props.bold?)
  elsif(char_props.bold?)
    if(@row)
      @format = @target.set_format(:bold) if @target
    elsif(@chapter && @chapter.sections.size == 1 \
          && @chapter.sections.first.empty? && check_exception?(text))
      # stay with the previous heading
    elsif(valid_chapter?(text))
      @chapter_flag = true
      @chapter = next_chapter
      @section = @chapter.next_section
      set_target(@chapter.heading)
    elsif(@chapter)
      @section = @chapter.next_section
      set_target(@section.subheading)
    end
  elsif(char_props.italic?)
    if(@chapter == @company)
      @chapter = next_chapter
    end
    if(@target.is_a?(Text::Paragraph) \
      && !@target.empty? && !@target.preformatted?)
      @format = @target.set_format(:italic)
    elsif(@chapter)
      @section = @chapter.next_section
      set_target(@section.subheading)
    end
  elsif(@format && @target.is_a?(Text::Paragraph))
    @format = nil
    @target.set_format
  elsif(!@in_table)
    # remove ' symbol of swissmedic number
    if text =~ /\(Swissmedic\)/
      text.gsub!(/(\d+).*?(\d+)/,'\1\2')
    end
    text.lstrip!
    ## sometimes, ill-formated colons are not appended to a subheading. 
    #  This is fixed manually here:
    if(text[0] == ?:)
      send_flowing_data(":")
      text[0,1] = ''
    end
    if(@chapter && !@chapter.include?(@section))
      @section = @chapter.next_section
    end
    target = if(@chapter && @target == @chapter.heading \
                && text.to_s.empty?)
               @chapter.heading
             elsif(@section)
               @section.next_paragraph
             end
    set_target(target)
  end
end

- (Object) row_end



135
136
137
# File 'ext/fiparse/src/fachinfo_doc.rb', line 135

def row_end
  @row = nil
end

- (Object) row_start(props)



126
127
128
129
130
131
132
133
134
# File 'ext/fiparse/src/fachinfo_doc.rb', line 126

def row_start(props)
  @row = props
  if( @table.nil? )
    @table = Text::Table.new
    @boundaries = []
  end
  @boundaries.push props.cell_boundaries
  @table.next_row!
end

- (Object) send_flowing_data(text)



138
139
140
141
142
143
144
145
146
147
148
# File 'ext/fiparse/src/fachinfo_doc.rb', line 138

def send_flowing_data(text)
  if(@table && @row.nil?)
    @section.paragraphs.compact!
    @section.paragraphs << @table
    fix_colspans
    @table = nil
    @boundaries = nil
    @target = @section.next_paragraph
  end
  super
end

- (Object) set_target(target)



149
150
151
152
# File 'ext/fiparse/src/fachinfo_doc.rb', line 149

def set_target(target)
  return if @row
  super
end

- (Boolean) valid_chapter?(text)

Returns:

  • (Boolean)


161
162
163
164
165
166
167
168
169
170
171
# File 'ext/fiparse/src/fachinfo_doc.rb', line 161

def valid_chapter?(text)
  case text.strip
  when "", '*', /Wirkstoffe/u, /Hilfsstoffe/u, /Klinische Wirksamkeit/u,
    /Atc.?code/iu, /Wirkungsmechanismus/u, /Absorption/u, /Metabolismus/u,
    /Haltbarkeit/u, /Lagerung/u, /Handhabung/u, /Tabe(lle)?/u, /^-/u,
    /Tableau/u
    false
  else
    true
  end
end