Class: IsoDoc::Gb::Cleanup

Inherits:
Object
  • Object
show all
Defined in:
lib/isodoc/gb/gbcleanup.rb

Instance Method Summary collapse

Constructor Details

#initialize(script, deprecated_lbl) ⇒ Cleanup

Returns a new instance of Cleanup.



4
5
6
7
# File 'lib/isodoc/gb/gbcleanup.rb', line 4

def initialize(script, deprecated_lbl)
  @script = script
  @deprecated_lbl = deprecated_lbl
end

Instance Method Details

#cleanup(docxml) ⇒ Object



9
10
11
12
13
14
# File 'lib/isodoc/gb/gbcleanup.rb', line 9

def cleanup(docxml)
  terms_cleanup(docxml)
  formula_cleanup(docxml)
  title_cleanup(docxml)
  docxml
end

#deprecated_single_label(docxml) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/isodoc/gb/gbcleanup.rb', line 61

def deprecated_single_label(docxml)
  docxml.xpath("//p[@class = 'DeprecatedTerms']").each do |d|
    t1 = d.previous_element
    next unless t1 && t1.name == "p" && t1["class"] == "DeprecatedTerms"
    d.children.first.content =
      d.children.first.content.sub(/^#{@deprecated_lbl}:\s*/, "")
  end
end

#example_cleanup(docxml) ⇒ Object



23
24
25
26
27
28
# File 'lib/isodoc/gb/gbcleanup.rb', line 23

def example_cleanup(docxml)
  docxml.xpath("//table[@class = 'Note']//p[not(@class)]").each do |p|
    p["class"] = "Note"
  end
  docxml
end

#formula_cleanup(docxml) ⇒ Object



16
17
18
19
20
21
# File 'lib/isodoc/gb/gbcleanup.rb', line 16

def formula_cleanup(docxml)
  docxml.xpath("//table[@class = 'dl']//p[not(@class)]").each do |p|
    p["class"] = "dl"
  end
  docxml
end

#spaerdruck(x, return_on_br) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/isodoc/gb/gbcleanup.rb', line 30

def spaerdruck(x, return_on_br)
  x.traverse do |n|
    n.text? and n.content = n.text.gsub(/(.)/, "\\1\u00a0\u00a0").
      gsub(/\u00a0+$/, "").gsub(/</, "&lt;").gsub(/>/, "&gt;")
    return_on_br and n.element? and n.name == "br" and return
  end
end

#term_merge(docxml, term_class) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/isodoc/gb/gbcleanup.rb', line 51

def term_merge(docxml, term_class)
  docxml.xpath("//p[@class = '#{term_class}']").each do |t|
    t1 = t.next_element || next
    if t1.name == "p" && t1["class"] == term_class
      t.add_child("&#x3000;")
      t.add_child(t1.remove.children)
    end
  end
end

#terms_cleanup(docxml) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/isodoc/gb/gbcleanup.rb', line 70

def terms_cleanup(docxml)
  term_merge(docxml, "Terms")
  term_merge(docxml, "AltTerms")
  deprecated_single_label(docxml)
  term_merge(docxml, "DeprecatedTerms")
  docxml
end

#title_cleanup(docxml) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/isodoc/gb/gbcleanup.rb', line 38

def title_cleanup(docxml)
  @script == "Hans" or return
  docxml.xpath("//*[@class = 'zzContents' or @class = 'ForewordTitle' or "\
               "@class = 'IntroTitle'] | "\
               "//h1[@class = 'Sections3']").each do |x|
    spaerdruck(x, false)
  end
  docxml.xpath("//h1[@class = 'Annex']").each do |x|
    spaerdruck(x, true)
  end
  docxml
end