Class: Metanorma::Bipm::Cleanup
- Inherits:
-
Generic::Cleanup
- Object
- Generic::Cleanup
- Metanorma::Bipm::Cleanup
- Defined in:
- lib/metanorma/bipm/cleanup.rb
Instance Method Summary collapse
- #bibdata_docidentifier_cleanup(isoxml) ⇒ Object
-
#bibdata_docidentifier_enhance(id, parts) ⇒ Object
not language-specific, just space-delimited.
- #bibdata_docidentifier_i18n(isoxml) ⇒ Object
- #bibdata_docidentifier_i18n_prep(isoxml) ⇒ Object
- #boilerplate_file(_xmldoc) ⇒ Object
- #copied_instance_variables ⇒ Object
- #jcgm_untitled_sections_cleanup(xml) ⇒ Object
- #mathml_mi_italics ⇒ Object
- #section_names_refs_cleanup(xml) ⇒ Object
- #section_names_terms_cleanup(xml) ⇒ Object
- #sections_cleanup(xml) ⇒ Object
- #sections_variant_title_cleanup(xml) ⇒ Object
- #xref_to_eref(elem, name) ⇒ Object
Instance Method Details
#bibdata_docidentifier_cleanup(isoxml) ⇒ Object
46 47 48 49 |
# File 'lib/metanorma/bipm/cleanup.rb', line 46 def bibdata_docidentifier_cleanup(isoxml) bibdata_docidentifier_i18n(isoxml) super end |
#bibdata_docidentifier_enhance(id, parts) ⇒ Object
not language-specific, just space-delimited
71 72 73 74 75 76 77 78 |
# File 'lib/metanorma/bipm/cleanup.rb', line 71 def bibdata_docidentifier_enhance(id, parts) ret = "" p = parts["part"] and ret += "-#{p}" p = parts["subpart"] and ret += "-#{p}" p = parts["appendix"] and ret += " A#{p}" p = parts["annexid"] and ret += ".#{p}" id.children = "#{id.text}#{ret}" end |
#bibdata_docidentifier_i18n(isoxml) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/metanorma/bipm/cleanup.rb', line 51 def bibdata_docidentifier_i18n(isoxml) id, parts = bibdata_docidentifier_i18n_prep(isoxml) parts.empty? and return id_alt = id.dup id.next = id_alt id_alt["type"] = "BIPM-parent-document" id_alt.delete("primary") bibdata_docidentifier_enhance(id, parts) end |
#bibdata_docidentifier_i18n_prep(isoxml) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/metanorma/bipm/cleanup.rb', line 61 def bibdata_docidentifier_i18n_prep(isoxml) id = isoxml.at("//bibdata/docidentifier[@type = 'BIPM']") parts = %w(appendix annexid part subpart).each_with_object({}) do |w, m| dn = isoxml.at("//bibdata/ext/structuredidentifier/#{w}") and m[w] = dn.text end [id, parts] end |
#boilerplate_file(_xmldoc) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/metanorma/bipm/cleanup.rb', line 8 def boilerplate_file(_xmldoc) if @jcgm File.join(File.dirname(__FILE__), "boilerplate-jcgm-en.adoc") else File.join(File.dirname(__FILE__), "boilerplate-#{@lang}.adoc") end end |
#copied_instance_variables ⇒ Object
4 5 6 |
# File 'lib/metanorma/bipm/cleanup.rb', line 4 def copied_instance_variables super + %i[jcgm] end |
#jcgm_untitled_sections_cleanup(xml) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/metanorma/bipm/cleanup.rb', line 21 def jcgm_untitled_sections_cleanup(xml) xml.xpath("//clause//clause | //annex//clause | //introduction/clause") .each do |c| !c&.at("./title")&.text&.empty? and next c["inline-header"] = true end end |
#mathml_mi_italics ⇒ Object
33 34 35 36 |
# File 'lib/metanorma/bipm/cleanup.rb', line 33 def mathml_mi_italics { uppergreek: false, upperroman: false, lowergreek: false, lowerroman: true } end |
#section_names_refs_cleanup(xml) ⇒ Object
31 |
# File 'lib/metanorma/bipm/cleanup.rb', line 31 def section_names_refs_cleanup(xml); end |
#section_names_terms_cleanup(xml) ⇒ Object
29 |
# File 'lib/metanorma/bipm/cleanup.rb', line 29 def section_names_terms_cleanup(xml); end |
#sections_cleanup(xml) ⇒ Object
16 17 18 19 |
# File 'lib/metanorma/bipm/cleanup.rb', line 16 def sections_cleanup(xml) super jcgm_untitled_sections_cleanup(xml) if @jcgm end |
#sections_variant_title_cleanup(xml) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/metanorma/bipm/cleanup.rb', line 80 def sections_variant_title_cleanup(xml) path = section_containers.map { |x| "./ancestor::#{x}" }.join(" | ") xml.xpath("//p[@variant_title]").each do |p| p.name = "variant-title" p.delete("variant_title") p.xpath("(#{path})[last()]").each do |sect| p.remove (ins = sect.at("./title") and ins.next = p) or sect.add_first_child(p) end end end |
#xref_to_eref(elem, name) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/metanorma/bipm/cleanup.rb', line 38 def xref_to_eref(elem, name) if elem.at("//bibitem[@anchor = '#{elem['target']}']/" \ "docidentifier[@type = 'BIPM-long']") elem["style"] = "BIPM-long" end super end |