Class: Metanorma::Iec::Cleanup
- Inherits:
-
Metanorma::Iso::Cleanup
- Object
- Metanorma::Iso::Cleanup
- Metanorma::Iec::Cleanup
- Extended by:
- Forwardable
- Defined in:
- lib/metanorma/iec/cleanup.rb
Instance Method Summary collapse
- #boilerplate_file(x_orig) ⇒ Object
- #copied_instance_variables ⇒ Object
- #docidentifier_cleanup(xmldoc) ⇒ Object
-
#get_id_prefix(xmldoc) ⇒ Object
TODO remove when I adopt pubid-iec.
- #id_prefix(_prefix, id) ⇒ Object
- #iev_variant_titles(xmldoc) ⇒ Object
- #note_cleanup(xmldoc) ⇒ Object
-
#ol_cleanup(doc) ⇒ Object
preserve ol/@type within boilerplate, not elsewhere in doc.
- #sections_names_pref_cleanup(xml) ⇒ Object
- #term_defs_boilerplate(div, source, term, preface, isodoc) ⇒ Object
- #terms_terms_cleanup(xmldoc) ⇒ Object
- #toc_cleanup(xmldoc) ⇒ Object
- #toc_iev_cleanup(xmldoc) ⇒ Object
Instance Method Details
#boilerplate_file(x_orig) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/metanorma/iec/cleanup.rb', line 9 def boilerplate_file(x_orig) lang = case x_orig&.at("//bibdata/language")&.text when "fr" then "fr" else "en" end File.join(@libdir, "boilerplate-#{lang}.adoc") end |
#copied_instance_variables ⇒ Object
5 6 7 |
# File 'lib/metanorma/iec/cleanup.rb', line 5 def copied_instance_variables super + %i[is_iev] end |
#docidentifier_cleanup(xmldoc) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/metanorma/iec/cleanup.rb', line 73 def docidentifier_cleanup(xmldoc) prefix = get_id_prefix(xmldoc) id = xmldoc.at("//bibdata/docidentifier[@type = 'ISO']") or return id.content = id_prefix(prefix, id) id = xmldoc.at("//bibdata/ext/structuredidentifier/project-number") and id.content = id_prefix(prefix, id) %w(iso-with-lang iso-reference iso-undated).each do |t| id = xmldoc.at("//bibdata/docidentifier[@type = '#{t}']") and id.content = id_prefix(prefix, id) end end |
#get_id_prefix(xmldoc) ⇒ Object
TODO remove when I adopt pubid-iec
86 87 88 89 90 91 92 93 |
# File 'lib/metanorma/iec/cleanup.rb', line 86 def get_id_prefix(xmldoc) xmldoc.xpath("//bibdata/contributor[role/@type = 'publisher']" \ "/organization").each_with_object([]) do |x, prefix| x1 = x.at("abbreviation")&.text || x.at("name")&.text # (x1 == "IEC" and prefix.unshift("IEC")) or prefix << x1 prefix << x1 end end |
#id_prefix(_prefix, id) ⇒ Object
95 96 97 |
# File 'lib/metanorma/iec/cleanup.rb', line 95 def id_prefix(_prefix, id) id.text end |
#iev_variant_titles(xmldoc) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/metanorma/iec/cleanup.rb', line 62 def iev_variant_titles(xmldoc) id = xmldoc&.at("//bibdata/docidentifier[@type = 'ISO']")&.text m = /60050-(\d+)/.match(id) or return xmldoc.xpath("//sections/clause/terms/title").each_with_index do |t, i| num = "%02d" % [i + 1] t.next = "<variant-title #{add_id_text} type='toc'>" \ "#{@i18n.section_iev} #{m[1]}-#{num} – " \ "#{t.children.to_xml}</variant-title>" end end |
#note_cleanup(xmldoc) ⇒ Object
47 48 49 50 51 |
# File 'lib/metanorma/iec/cleanup.rb', line 47 def note_cleanup(xmldoc) super n = xmldoc.at("//tc-sc-officers-note") and xmldoc.at("//bibdata/ext").add_child(n.remove) end |
#ol_cleanup(doc) ⇒ Object
preserve ol/@type within boilerplate, not elsewhere in doc
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/metanorma/iec/cleanup.rb', line 34 def ol_cleanup(doc) doc.xpath("//ol[@type]").each { |x| x.delete("type") } if doc.at("//metanorma-extension/semantic-metadata/" \ "headless[text() = 'true']") doc.xpath("//ol[@explicit-type]").each do |x| x["type"] = x["explicit-type"] x.delete("explicit-type") end end ::Metanorma::Standoc::Cleanup.instance_method(:ol_cleanup).bind(self) .call(doc) end |
#sections_names_pref_cleanup(xml) ⇒ Object
27 28 29 30 31 |
# File 'lib/metanorma/iec/cleanup.rb', line 27 def sections_names_pref_cleanup(xml) super @is_iev and replace_title(xml, "//introduction", @i18n&.introduction_iev) end |
#term_defs_boilerplate(div, source, term, preface, isodoc) ⇒ Object
18 19 20 |
# File 'lib/metanorma/iec/cleanup.rb', line 18 def term_defs_boilerplate(div, source, term, preface, isodoc) super unless @is_iev end |
#terms_terms_cleanup(xmldoc) ⇒ Object
22 23 24 25 |
# File 'lib/metanorma/iec/cleanup.rb', line 22 def terms_terms_cleanup(xmldoc) @is_iev and return super end |
#toc_cleanup(xmldoc) ⇒ Object
53 54 55 56 |
# File 'lib/metanorma/iec/cleanup.rb', line 53 def toc_cleanup(xmldoc) toc_iev_cleanup(xmldoc) if @is_iev super end |
#toc_iev_cleanup(xmldoc) ⇒ Object
58 59 60 |
# File 'lib/metanorma/iec/cleanup.rb', line 58 def toc_iev_cleanup(xmldoc) iev_variant_titles(xmldoc) end |