Class: Metanorma::Jis::Cleanup
- Inherits:
-
Iso::Cleanup
- Object
- Iso::Cleanup
- Metanorma::Jis::Cleanup
- Defined in:
- lib/metanorma/jis/cleanup.rb
Instance Method Summary collapse
- #bibdata_cleanup(xmldoc) ⇒ Object
- #bibdata_supply_chairperson_role(xmldoc) ⇒ Object
- #biblio_reorder(xmldoc) ⇒ Object
- #boilerplate_file(_x_orig) ⇒ Object
- #clean_example_keep_separate(xmldoc) ⇒ Object
-
#default_publisher_sort ⇒ Object
JIS first, then ISO, then IEC, then other standards, then everything else.
- #docidentifier_cleanup(xmldoc) ⇒ Object
- #norm_ref_preface(ref, isodoc) ⇒ Object
- #note_cleanup(xmldoc) ⇒ Object
- #note_example_to_table(xmldoc) ⇒ Object
- #ol_cleanup(doc) ⇒ Object
- #pub_class(bib) ⇒ Object
- #ref_dated(ref) ⇒ Object
- #ref_empty?(ref) ⇒ Boolean
- #second_pub_class(bib, _first_pub = nil) ⇒ Object
- #table_footnote_renumber(xmldoc) ⇒ Object
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 |
#default_publisher_sort ⇒ Object
JIS first, then ISO, then IEC, then other standards, then everything
else. A co-publisher is ordered by the secondary key (see
Standoc::Ref#publisher_sort_second), which reproduces the historical
JIS ordering: JIS+IEC before JIS+ISO, JIS+IEC+ISO alongside JIS+IEC.
Built at runtime because the JIS publisher name is language-dependent
(@conv.pub_hash). Overridable per-document / per-taste via
:sort-biblio-
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/metanorma/jis/cleanup.rb', line 103 def default_publisher_sort [ { abbrev: "JIS", name: [@conv.pub_hash["ja"], @conv.pub_hash["en"]].compact, rank: 1 }, { abbrev: "ISO", name: "International Organization for Standardization", rank: 2 }, { abbrev: "IEC", name: "International Electrotechnical Commission", rank: 3 }, ] 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
115 116 117 |
# File 'lib/metanorma/jis/cleanup.rb', line 115 def pub_class(bib) publisher_sort_rank(bib, default_publisher_sort) 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
19 20 21 |
# File 'lib/metanorma/jis/cleanup.rb', line 19 def ref_empty?(ref) ref.xpath(".//bibitem").empty? end |
#second_pub_class(bib, _first_pub = nil) ⇒ Object
119 120 121 |
# File 'lib/metanorma/jis/cleanup.rb', line 119 def second_pub_class(bib, _first_pub = nil) publisher_sort_second(bib, default_publisher_sort) 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 |