Class: Metanorma::Jis::Cleanup

Inherits:
Iso::Cleanup
  • Object
show all
Defined in:
lib/metanorma/jis/cleanup.rb

Instance Method Summary collapse

Instance Method Details

#bibdata_cleanup(xmldoc) ⇒ Object



69
70
71
72
# File 'lib/metanorma/jis/cleanup.rb', line 69

def bibdata_cleanup(xmldoc)
  super
  bibdata_supply_chairperson_role(xmldoc)
end

#bibdata_supply_chairperson_role(xmldoc) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/metanorma/jis/cleanup.rb', line 74

def bibdata_supply_chairperson_role(xmldoc)
  xpath =
    "//bibdata/contributor" \
    "[role/@type = 'authorizer'][role/description = " \
    "'investigative committee']/person/affiliation"
  xmldoc.xpath(xpath).each do |a|
    a.at("./name") or next
    a.children.first.previous = "<name>#{@i18n.chairperson}</name>"
  end
end

#biblio_reorder(xmldoc) ⇒ Object



90
91
92
93
94
# File 'lib/metanorma/jis/cleanup.rb', line 90

def biblio_reorder(xmldoc)
  xmldoc.xpath("//references[@normative = 'true']").each do |r|
    biblio_reorder1(r)
  end
end

#boilerplate_file(_x_orig) ⇒ Object



4
5
6
# File 'lib/metanorma/jis/cleanup.rb', line 4

def boilerplate_file(_x_orig)
  File.join(@libdir, "boilerplate-#{@lang}.adoc")
end

#clean_example_keep_separate(xmldoc) ⇒ Object



62
63
64
65
66
67
# File 'lib/metanorma/jis/cleanup.rb', line 62

def clean_example_keep_separate(xmldoc)
  xmldoc.xpath("//example[@keep-separate] | " \
               "//termexample[@keep-separate]").each do |n|
    n.delete("keep-separate")
  end
end

#docidentifier_cleanup(xmldoc) ⇒ Object



44
# File 'lib/metanorma/jis/cleanup.rb', line 44

def docidentifier_cleanup(xmldoc); end

#norm_ref_preface(ref, isodoc) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/metanorma/jis/cleanup.rb', line 8

def norm_ref_preface(ref, isodoc)
  if ref.at("./note[@type = 'boilerplate']")
    unwrap_boilerplate_clauses(ref, ".")
  else
    pref = if ref_empty?(ref) then @i18n.norm_empty_pref
           else @i18n.get[ref_dated(ref)]
           end
    ref.at("./title").next = boilerplate_snippet_convert(pref, isodoc)
  end
end

#note_cleanup(xmldoc) ⇒ Object



46
47
48
49
50
# File 'lib/metanorma/jis/cleanup.rb', line 46

def note_cleanup(xmldoc)
  note_example_to_table(xmldoc)
  super
  clean_example_keep_separate(xmldoc)
end

#note_example_to_table(xmldoc) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/metanorma/jis/cleanup.rb', line 52

def note_example_to_table(xmldoc)
  xmldoc.xpath("//table").each do |t|
    t.xpath("./following-sibling::*").each do |n|
      %w(note example).include?(n.name) or break
      n["keep-separate"] == "true" and break
      n.parent = t
    end
  end
end

#ol_cleanup(doc) ⇒ Object



85
86
87
88
# File 'lib/metanorma/jis/cleanup.rb', line 85

def ol_cleanup(doc)
  ::Metanorma::Standoc::Cleanup.instance_method(:ol_cleanup).bind(self)
    .call(doc)
end

#pub_class(bib) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/metanorma/jis/cleanup.rb', line 109

def pub_class(bib)
  iso, iec, jis = pub_class_prep(bib)
  jis && iec && iso and return 2
  jis && iec and return 2
  jis && iso and return 3
  jis and return 1
  iso && iec and return 4
  iso and return 4
  iec and return 5
  6
end

#pub_class_prep(bib) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/metanorma/jis/cleanup.rb', line 96

def pub_class_prep(bib)
  iso = bib.at("#{PUBLISHER}[abbreviation = 'ISO']") ||
    bib.at("#{PUBLISHER}[name = 'International Organization " \
                             "for Standardization']")
  iec = bib.at("#{PUBLISHER}[abbreviation = 'IEC']") ||
    bib.at("#{PUBLISHER}[name = 'International " \
                             "Electrotechnical Commission']")
  jis = bib.at("#{PUBLISHER}[abbreviation = 'JIS']") ||
    bib.at("#{PUBLISHER}[name = '#{@conv.pub_hash['ja']}']") ||
    bib.at("#{PUBLISHER}[name = '#{@conv.pub_hash['en']}']")
  [iso, iec, jis]
end

#ref_dated(ref) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/metanorma/jis/cleanup.rb', line 23

def ref_dated(ref)
  refs = ref.xpath("./bibitem").each_with_object({}) do |e, m|
    if e.at("./date") then m[:dated] = true
    else m[:undated] = true
    end
  end
  refs[:dated] && refs[:undated] and return "norm_with_refs_pref"
  refs[:dated] and return "norm_with_refs_pref_all_dated"
  "norm_with_refs_pref_none_dated"
end

#ref_empty?(ref) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/metanorma/jis/cleanup.rb', line 19

def ref_empty?(ref)
  ref.xpath(".//bibitem").empty?
end

#table_footnote_renumber(xmldoc) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/metanorma/jis/cleanup.rb', line 34

def table_footnote_renumber(xmldoc)
  xmldoc.xpath("//table | //figure").each do |t|
    seen = {}
    i = 0
    t.xpath(".//fn").each do |fn|
      i, seen = table_footnote_renumber1(fn, i, seen)
    end
  end
end