Class: YDocx::Parser

Inherits:
Object
  • Object
show all
Includes:
MarkupMethod
Defined in:
lib/ydocx/parser.rb,
lib/ydocx/templates/patinfo.rb,
lib/ydocx/templates/fachinfo.rb

Constant Summary collapse

@@figure_pattern =
/‘|’|'|´/

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MarkupMethod

#markup

Constructor Details

#initialize(doc, rel) ⇒ Parser

Returns a new instance of Parser.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ydocx/parser.rb', line 12

def initialize(doc, rel)
  @doc = Nokogiri::XML.parse(doc)
  @rel = Nokogiri::XML.parse(rel)
  @coder = HTMLEntities.new
  @indecies = []
  @images = []
  @result = []
  @space = ' '
  @image_path = 'images'
  @image_style = ''
  init
  if block_given?
    yield self
  end
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



8
9
10
# File 'lib/ydocx/templates/fachinfo.rb', line 8

def code
  @code
end

#imagesObject

Returns the value of attribute images.



11
12
13
# File 'lib/ydocx/parser.rb', line 11

def images
  @images
end

#indeciesObject

Returns the value of attribute indecies.



11
12
13
# File 'lib/ydocx/parser.rb', line 11

def indecies
  @indecies
end

#langObject

Returns the value of attribute lang.



11
12
13
# File 'lib/ydocx/parser.rb', line 11

def lang
  @lang
end

#resultObject

Returns the value of attribute result.



11
12
13
# File 'lib/ydocx/parser.rb', line 11

def result
  @result
end

#spaceObject

Returns the value of attribute space.



11
12
13
# File 'lib/ydocx/parser.rb', line 11

def space
  @space
end

Instance Method Details

#chaptersObject

Fachinfo Chapters

1. name
2. composition
3. galenic form
4. indications
5. usage
6. contra_indications
7. restrictions
8. interactions
9. pregnancy
  1. driving_ability

  2. unwanted_effects

  3. overdose

  4. effects

  5. kinetic

  6. preclinic

  7. other_advice

  8. iksnr

  9. packages

  10. registration_owner

  11. date



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ydocx/templates/fachinfo.rb', line 37

def chapters
  # TODO
  # Franzoesisch
  chapters = {
    'Information'         => /^Information\s+für\sPatientinnen\s+und\s+Patienten$/u, # 1
    'Name'                => /^Name\s+des\s+Präparates$/u, # 2
    'Eigensch.'           => /^Was\s+ist\s+\w+\s+und\s+wann\s+wird\s+es\s+angewendet\s*\??$/u, # 3
    'Abänderung'     => /^Was\s+sollte\s+dazu\s+beachtet\s+werden\s*\??$/u, # 4
    'Kontraind.'          => /^Wann\s+darf\s+\w+\s+nicht\s+(eingenommen\s*\/\s*angewendet|eingenommen|angewendet)\s*werden\s*\??$/u, # 5
    'Vorbeugung'          => /^Wann\s+ist\s+bei\s+der\s+(Einnahme\s*\/\s*Anwendung|Einnahme|Anwendung)\s*von\s+\w+\s+Vorsicht\s+geboten\s*\??$/u, # 6
    'Schwanderschaft'     => /^Darf\s+\w+\s+während\s+einer\s+Schwangerschaft\s+oder\s+in\s+der\s+Stillzeit\s+(eingenommen\s*\/\s*angewendet|eingenommen|angewendet)\s*werden\s*\??$/u, # 7
    'Dos./Anw.'           => /^Wie\s+verwenden\s+Sie\s+\w+\s*\??$/u, # 8
    'Unerw.Wirkungen'     => /^Welche\s+Nebenwirkungen\s+kann\s+\w+\s+haben\s*\??$/u, # 9
    'Gewöhnliche H.' => /^Was\s+ist\s+ferner\s+zu\s+beachten\s*\??$/u, # 10
    'Zusammens.'          => /^Was\s+ist\s+in\s+\w+\s+enthalten\s*\??$/u, # 11
    'Swissmedic-Nr.'      => /^Zulassungsnummer$/u, # 12
    'Packungen'           => /^Wo\s+erhalten\s+Sie\s+\w+\s*\?\s*Welche\s+Packungen\s+sind\s+erhältlich\s*\??$/u, # 13
    'Verteiler'           => /^Zulassungsinhaberin$/u, # 14
    'Hersteller'          => /^Herstellerin$/u, # 15
    'Stand d. Info.'      => /^Diese\sPackungsbeilage\s+wurde\s+im\s+[\.A-z\s0-9]+(\s+|\s*\/\s*\w+\s+\(Monat\s*\/\s*Jahr\)\s*)letztmals\s+durch\s+die\s+Arzneimittelbehörde\s*\(\s*Swissmedic\s*\)\s*geprüft.?$/u, # 16
  }
end

#initObject



27
28
# File 'lib/ydocx/parser.rb', line 27

def init
end

#parseObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ydocx/parser.rb', line 29

def parse
  @doc.xpath('//w:document//w:body').children.map do |node|
    case node.node_name
    when 'text'
      @result << parse_paragraph(node)
    when 'tbl'
      @result << parse_table(node)
    when 'p'
      @result << parse_paragraph(node)
    else
      # skip
    end
  end
  @result
end