Class: ODDB::FiParse::FachinfoDocWriter

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

Instance Attribute Summary collapse

Attributes inherited from Writer

#chapters, #iksnrs, #name

Instance Method Summary collapse

Methods included from FachinfoWriterMethods

#to_fachinfo

Methods inherited from Writer

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

Constructor Details

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

Instance Attribute Details

#cutoff_fontsizeObject

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

Instance Method Details

#cell_endObject



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

def cell_end
  #@target = nil
end

#cell_startObject



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

#check_exception?(text) ⇒ Boolean

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

#complete?Boolean

Returns:

  • (Boolean)


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

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

#fix_colspansObject



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

#new_font(char_props, text = nil) ⇒ Object



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

#row_endObject



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

def row_end
  @row = nil
end

#row_start(props) ⇒ Object



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

#send_flowing_data(text) ⇒ Object



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

#set_target(target) ⇒ Object



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

def set_target(target)
  return if @row
  super
end

#valid_chapter?(text) ⇒ Boolean

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