Class: Metanorma::ITU::Converter
- Inherits:
-
Standoc::Converter
- Object
- Standoc::Converter
- Metanorma::ITU::Converter
- Defined in:
- lib/metanorma/itu/front.rb,
lib/metanorma/itu/cleanup.rb,
lib/metanorma/itu/front_id.rb,
lib/metanorma/itu/validate.rb,
lib/metanorma/itu/converter.rb,
lib/metanorma/itu/cleanup_section.rb
Constant Summary collapse
- PUBLISHER =
"./contributor[role/@type = 'publisher']/organization".freeze
- ITULANG =
{ "en" => "E", "fr" => "F", "ar" => "A", "es" => "S", "zh" => "C", "ru" => "R" }.freeze
- XML_ROOT_TAG =
"itu-standard".freeze
- XML_NAMESPACE =
"https://www.metanorma.org/ns/itu".freeze
Instance Method Summary collapse
- #add_id ⇒ Object
- #approval_validate(xmldoc) ⇒ Object
- #bibdata_cleanup(xmldoc) ⇒ Object
- #bibdata_validate(doc) ⇒ Object
- #biblio_reorder(xmldoc) ⇒ Object
- #boilerplate_file(_xmldoc) ⇒ Object
- #clause_parse(attrs, xml, node) ⇒ Object
- #cleanup(xmldoc) ⇒ Object
- #content_validate(doc) ⇒ Object
- #coverpage_images(xmldoc) ⇒ Object
- #default_publisher ⇒ Object
- #doc_converter(node) ⇒ Object
- #doc_extract_attributes(node) ⇒ Object
- #doctype_validate(_xmldoc) ⇒ Object
- #document_scheme(node) ⇒ Object
- #extract_text(node) ⇒ Object
- #group_period(node, prefix, suffix) ⇒ Object
- #header_rows_cleanup(xmldoc) ⇒ Object
- #html_converter(node) ⇒ Object
- #html_extract_attributes(node) ⇒ Object
- #hyphenate_node_attributes(node) ⇒ Object
- #init(node) ⇒ Object
- #init_misc(node) ⇒ Object
- #insert_conventions(xml) ⇒ Object
- #insert_empty_clauses(xml) ⇒ Object
- #insert_empty_clauses1(clause, text) ⇒ Object
- #insert_missing_sections(xml) ⇒ Object
- #insert_norm_ref(xml) ⇒ Object
- #insert_scope(xml) ⇒ Object
- #insert_symbols(xml) ⇒ Object
- #insert_terms(xml) ⇒ Object
- #insert_title(xml, type, lang, content) ⇒ Object
- #itu_contrib_id(node) ⇒ Object
- #itu_id(node, xml) ⇒ Object
- #itu_id1(node, lang) ⇒ Object
- #itu_identifier_validate(xmldoc) ⇒ Object
- #itu_service_pub_id(node) ⇒ Object
- #makexml(node) ⇒ Object
- #metadata_committee(node, xml) ⇒ Object
- #metadata_committee1(node, xml, suffix) ⇒ Object
- #metadata_committee2(node, group, suffix, prefix) ⇒ Object
- #metadata_contribution(node, xml) ⇒ Object
- #metadata_coverpage_images(node, xml) ⇒ Object
- #metadata_ext(node, xml) ⇒ Object
- #metadata_id(node, xml) ⇒ Object
- #metadata_ip_notice(node, xml) ⇒ Object
- #metadata_keywords(node, xml) ⇒ Object
- #metadata_meeting(mtg, acronym, xml) ⇒ Object
- #metadata_meeting_date(val, xml) ⇒ Object
- #metadata_question(node, xml) ⇒ Object
- #metadata_recommendationstatus(node, xml) ⇒ Object
- #metadata_sector(node, xml) ⇒ Object
- #metadata_series(node, xml) ⇒ Object
- #metadata_status(node, xml) ⇒ Object
- #metadata_techreport(node, xml) ⇒ Object
-
#numbers_validate(xmldoc) ⇒ Object
Editing Guidelines 9.4.3 Supplanted by rendering.
- #olist(node) ⇒ Object
- #org_abbrev ⇒ Object
- #other_title_defaultlang(node, xml, type) ⇒ Object
- #other_title_otherlangs(node, xml, type) ⇒ Object
- #outputs(node, ret) ⇒ Object
- #pdf_converter(node) ⇒ Object
- #personal_role(node, contrib, suffix) ⇒ Object
- #presentation_xml_converter(node) ⇒ Object
- #provisional_id(node, xml) ⇒ Object
- #pub_class(bib) ⇒ Object
- #recommendation_id(node, xml) ⇒ Object
- #relaton_relations ⇒ Object
-
#reqt_validate(xmldoc) ⇒ Object
Editing Guidelines 7.
- #resolution_inline_header(xml) ⇒ Object
-
#section_check(xmldoc) ⇒ Object
Editing Guidelines 7.2, 7.3.
- #section_names_terms_cleanup(xml) ⇒ Object
- #section_validate(doc) ⇒ Object
- #sections_cleanup(xml) ⇒ Object
- #sections_names_pref_cleanup(xml) ⇒ Object
- #sectiontype(node, level = true) ⇒ Object
- #sectiontype_streamline(ret) ⇒ Object
- #smartquotes_cleanup(xmldoc) ⇒ Object
- #sort_biblio(bib) ⇒ Object
-
#sort_biblio_key(bib) ⇒ Object
sort by: doc class (ITU, ISO, IEC, other standard (not DOI &c), other then standard class (docid class other than DOI &c) then alphanumeric doc id (not DOI &c) then title.
- #stage_validate(xmldoc) ⇒ Object
- #structured_id(node, xml) ⇒ Object
- #style(_node, _text) ⇒ Object
- #style_two_regex_not_prev(node, text, regex, regex_prev, warning) ⇒ Object
- #symbols_cleanup(xmldoc) ⇒ Object
- #table_cleanup(xmldoc) ⇒ Object
- #td_id(node, xml) ⇒ Object
- #term_def_subclause_parse(attrs, xml, node) ⇒ Object
- #term_defs_boilerplate(div, _source, _term, _preface, _isodoc) ⇒ Object
- #termdef_boilerplate_cleanup(xmldoc) ⇒ Object
- #termdef_style(xmldoc) ⇒ Object
- #termdef_warn(text, regex, node, term, msg) ⇒ Object
- #terms_extract(div) ⇒ Object
- #title(node, xml) ⇒ Object
- #title_defaultlang(node, xml) ⇒ Object
- #title_otherlangs(node, xml) ⇒ Object
- #title_validate(_root) ⇒ Object
-
#title_validate1(xmldoc) ⇒ Object
Editing Guidelines 6.3.
- #unnumbered_check(xmldoc) ⇒ Object
- #validate(doc) ⇒ Object
Instance Method Details
#add_id ⇒ Object
29 30 31 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 29 def add_id %(id="_#{UUIDTools::UUID.random_create}") end |
#approval_validate(xmldoc) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/metanorma/itu/validate.rb', line 86 def approval_validate(xmldoc) s = xmldoc.at("//bibdata/ext/recommendationstatus/approvalstage") or return process = s["process"] (process == "aap") && %w(determined in-force).include?(s.text) and @log.add("Document Attributes", nil, "Recommendation Status #{s.text} inconsistent with AAP") (process == "tap") && !%w(determined in-force).include?(s.text) and @log.add("Document Attributes", nil, "Recommendation Status #{s.text} inconsistent with TAP") end |
#bibdata_cleanup(xmldoc) ⇒ Object
86 87 88 89 |
# File 'lib/metanorma/itu/cleanup.rb', line 86 def bibdata_cleanup(xmldoc) super coverpage_images(xmldoc) end |
#bibdata_validate(doc) ⇒ Object
4 5 6 7 |
# File 'lib/metanorma/itu/validate.rb', line 4 def bibdata_validate(doc) doctype_validate(doc) stage_validate(doc) end |
#biblio_reorder(xmldoc) ⇒ Object
80 81 82 83 84 |
# File 'lib/metanorma/itu/cleanup.rb', line 80 def biblio_reorder(xmldoc) xmldoc.xpath("//references").each do |r| biblio_reorder1(r) end end |
#boilerplate_file(_xmldoc) ⇒ Object
29 30 31 |
# File 'lib/metanorma/itu/converter.rb', line 29 def boilerplate_file(_xmldoc) File.join(@libdir, "boilerplate.adoc") end |
#clause_parse(attrs, xml, node) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/metanorma/itu/converter.rb', line 118 def clause_parse(attrs, xml, node) node.option?("unnumbered") and attrs[:unnumbered] = true case sectiontype1(node) when "conventions" then attrs = attrs.merge(type: "conventions") when "history", "source" attrs[:preface] and attrs = attrs.merge(type: sectiontype1(node)) end super end |
#cleanup(xmldoc) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/metanorma/itu/cleanup.rb', line 21 def cleanup(xmldoc) symbols_cleanup(xmldoc) super obligations_cleanup(xmldoc) xmldoc end |
#content_validate(doc) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/metanorma/itu/validate.rb', line 27 def content_validate(doc) super approval_validate(doc) itu_identifier_validate(doc) bibdata_validate(doc.root) termdef_style(doc.root) title_validate1(doc.root) reqt_validate(doc.root) numbers_validate(doc.root) end |
#coverpage_images(xmldoc) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/metanorma/itu/cleanup.rb', line 91 def coverpage_images(xmldoc) %w(coverpage-image).each do |n| xmldoc.xpath("//bibdata/ext/#{n}").each do |x| ins = add_misc_container(xmldoc) ins << "<presentation-metadata><name>#{n}</name>" \ "<value>#{x.remove.children.to_xml}</value>" \ "</presentation-metadata>" end end end |
#default_publisher ⇒ Object
66 67 68 |
# File 'lib/metanorma/itu/front.rb', line 66 def default_publisher @i18n.get["ITU"] || @i18n.international_telecommunication_union end |
#doc_converter(node) ⇒ Object
157 158 159 |
# File 'lib/metanorma/itu/converter.rb', line 157 def doc_converter(node) IsoDoc::ITU::WordConvert.new(doc_extract_attributes(node)) end |
#doc_extract_attributes(node) ⇒ Object
137 138 139 140 |
# File 'lib/metanorma/itu/converter.rb', line 137 def doc_extract_attributes(node) super.merge(hierarchicalassets: node.attr("hierarchical-object-numbering")) end |
#doctype_validate(_xmldoc) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/metanorma/itu/validate.rb', line 9 def doctype_validate(_xmldoc) %w(recommendation recommendation-supplement recommendation-amendment recommendation-corrigendum recommendation-errata recommendation-annex focus-group implementers-guide technical-paper technical-report joint-itu-iso-iec service-publication contribution).include? @doctype or @log.add("Document Attributes", nil, "#{@doctype} is not a recognised document type") end |
#document_scheme(node) ⇒ Object
128 129 130 |
# File 'lib/metanorma/itu/converter.rb', line 128 def document_scheme(node) super || "current" end |
#extract_text(node) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/metanorma/itu/validate.rb', line 49 def extract_text(node) return "" if node.nil? node1 = Nokogiri::XML.fragment(node.to_s) node1.xpath("//link | //locality | //localityStack").each(&:remove) ret = "" node1.traverse { |x| ret += x.text if x.text? } ret end |
#group_period(node, prefix, suffix) ⇒ Object
141 142 143 144 145 146 |
# File 'lib/metanorma/itu/front.rb', line 141 def group_period(node, prefix, suffix) s = node.attr("#{prefix}group-year-start#{suffix}") || Date.today.year - (Date.today.year % 2) e = node.attr("#{prefix}group-year-end#{suffix}") || s.to_i + 2 [s, e] end |
#header_rows_cleanup(xmldoc) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/metanorma/itu/cleanup.rb', line 14 def header_rows_cleanup(xmldoc) super xmldoc.xpath("//table/thead/tr/th").each do |x| x["align"] = "center" end end |
#html_converter(node) ⇒ Object
149 150 151 |
# File 'lib/metanorma/itu/converter.rb', line 149 def html_converter(node) IsoDoc::ITU::HtmlConvert.new(html_extract_attributes(node)) end |
#html_extract_attributes(node) ⇒ Object
132 133 134 135 |
# File 'lib/metanorma/itu/converter.rb', line 132 def html_extract_attributes(node) super.merge(hierarchicalassets: node.attr("hierarchical-object-numbering")) end |
#hyphenate_node_attributes(node) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/metanorma/itu/front.rb', line 88 def hyphenate_node_attributes(node) a = node.attributes.dup a.each do |k, v| /group(type|acronym)/.match?(k) and node.set_attr(k.sub(/group(type|acronym)/, "group-\\1"), v) /group(yearstart|yearend)/.match?(k) and node.set_attr(k.sub(/groupyear(start|end)/, "group-year-\\1"), v) end end |
#init(node) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/metanorma/itu/converter.rb', line 21 def init(node) super @smartquotes = node.attr("smartquotes") == "true" @no_insert_missing_sections = doctype(node) != "recommendation" || node.attr("legacy-do-not-insert-missing-sections") || node.attr("document-schema") == "legacy" end |
#init_misc(node) ⇒ Object
38 39 40 41 |
# File 'lib/metanorma/itu/converter.rb', line 38 def init_misc(node) super @default_doctype = "recommendation" end |
#insert_conventions(xml) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 72 def insert_conventions(xml) ins = xml.at("//sections//definitions") || xml.at("//sections/clause[descendant::definitions]") unless xml.at("//sections/clause[@type = 'conventions']") ins.next = "<clause #{add_id} type='conventions'>" \ "<title>#{@i18n.conventions}</title><p>" \ "#{@i18n.clause_empty}</p></clause>" end end |
#insert_empty_clauses(xml) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 82 def insert_empty_clauses(xml) xml.xpath("//terms[not(./term)][not(.//terms)]").each do |c| insert_empty_clauses1(c, @i18n.clause_empty) end xml.xpath("//definitions[not(./dl)]").each do |c| insert_empty_clauses1(c, @i18n.clause_empty) end end |
#insert_empty_clauses1(clause, text) ⇒ Object
91 92 93 94 95 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 91 def insert_empty_clauses1(clause, text) clause.at("./p") and return ins = clause.at("./title") or return ins.next = "<p>#{text}</p>" end |
#insert_missing_sections(xml) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 19 def insert_missing_sections(xml) xml.at("//metanorma-extension/semantic-metadata/" \ "headless[text() = 'true']") and return nil insert_scope(xml) insert_norm_ref(xml) insert_terms(xml) insert_symbols(xml) insert_conventions(xml) end |
#insert_norm_ref(xml) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 46 def insert_norm_ref(xml) xml.at("//bibliography") or xml.at("./*/annex[last()] | ./*/sections").next = "<bibliography><sentinel/></bibliography>" ins = xml.at("//bibliography").elements.first xml.at("//bibliography/references[@normative = 'true']") or ins.previous = "<references #{add_id} normative='true'>" \ "<title>#{@i18n.normref}</title></references>" xml.at("//sentinel")&.remove end |
#insert_scope(xml) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 33 def insert_scope(xml) xml.at("./*/sections") or xml.at("./*/preface | ./*/boilerplate | ./*/bibdata").next = "<sections><sentinel/></sections>" xml.at("./*/sections/*") or xml.at("./*/sections") << "<sentinel/>" ins = xml.at("//sections").elements.first xml.at("//sections/clause[@type = 'scope']") or ins.previous = "<clause type='scope' #{add_id}><title>#{@i18n.scope}</title><p>" \ "#{@i18n.clause_empty}</p></clause>" xml.at("//sentinel")&.remove end |
#insert_symbols(xml) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 63 def insert_symbols(xml) ins = xml.at("//sections/terms") || xml.at("//sections/clause[descendant::terms]") unless xml.at("//sections//definitions") ins.next = "<definitions #{add_id}>" \ "<title>#{@i18n.symbolsabbrev}</title></definitions>" end end |
#insert_terms(xml) ⇒ Object
57 58 59 60 61 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 57 def insert_terms(xml) ins = xml.at("//sections/clause[@type = 'scope']") xml.at("//sections//terms") or ins.next = "<terms #{add_id}><title>#{@i18n.termsdef}</title></terms>" end |
#insert_title(xml, type, lang, content) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/metanorma/itu/front.rb', line 19 def insert_title(xml, type, lang, content) attr = { language: lang, format: "text/plain", type: type } xml.title **attr_code(attr) do |t| t << Metanorma::Utils::asciidoc_sub(content) end end |
#itu_contrib_id(node) ⇒ Object
45 46 47 48 49 |
# File 'lib/metanorma/itu/front_id.rb', line 45 def itu_contrib_id(node) group = node.attr("group-acronym") || node.attr("group").sub("Study Group ", "SG") "#{group}-C#{node.attr('docnumber')}" end |
#itu_id(node, xml) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/metanorma/itu/front_id.rb', line 51 def itu_id(node, xml) node.attr("docnumber") || node.attr("docidentifier") or return xml.docidentifier type: "ITU", primary: "true" do |i| i << (node.attr("docidentifier") || itu_id1(node, false)) end xml.docidentifier type: "ITU-lang" do |i| i << itu_id1(node, true) end end |
#itu_id1(node, lang) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/metanorma/itu/front_id.rb', line 28 def itu_id1(node, lang) bureau = node.attr("bureau") || "T" id = case doctype(node) when "service-publication" itu_service_pub_id(node) when "contribution" itu_contrib_id(node) else "ITU-#{bureau} #{node.attr('docnumber')}" end id + (lang ? "-#{ITULANG[@lang]}" : "") end |
#itu_identifier_validate(xmldoc) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/metanorma/itu/validate.rb', line 98 def itu_identifier_validate(xmldoc) xmldoc.xpath("//bibdata/docidentifier[@type = 'ITU']").each do |x| /^ITU-[RTD] [AD-VX-Z]\.\d+(\.\d+)?$/.match(x.text) or @log.add("Style", nil, "#{x.text} does not match ITU document " \ "identifier conventions") end end |
#itu_service_pub_id(node) ⇒ Object
41 42 43 |
# File 'lib/metanorma/itu/front_id.rb', line 41 def itu_service_pub_id(node) @i18n.annex_to_itu_ob_abbrev.sub(/%/, node.attr("docnumber")) end |
#makexml(node) ⇒ Object
33 34 35 36 |
# File 'lib/metanorma/itu/converter.rb', line 33 def makexml(node) @draft = node.attributes.has_key?("draft") super end |
#metadata_committee(node, xml) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/metanorma/itu/front.rb', line 76 def (node, xml) hyphenate_node_attributes(node) (node, xml) (node, xml, "") suffix = 2 while node.attr("bureau_#{suffix}") (node, xml, "_#{suffix}") suffix += 1 end (node, xml) end |
#metadata_committee1(node, xml, suffix) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/metanorma/itu/front.rb', line 118 def (node, xml, suffix) xml.editorialgroup do |a| a.bureau ( node.attr("bureau#{suffix}") || "T") ["", "sub", "work"].each do |p| node.attr("#{p}group#{suffix}") or next type = node.attr("#{p}group-type#{suffix}") a.send "#{p}group", **attr_code(type: type) do |g| (node, g, suffix, p) end end end end |
#metadata_committee2(node, group, suffix, prefix) ⇒ Object
131 132 133 134 135 136 137 138 139 |
# File 'lib/metanorma/itu/front.rb', line 131 def (node, group, suffix, prefix) group.name node.attr("#{prefix}group#{suffix}") a = node.attr("#{prefix}group-acronym#{suffix}") and group.acronym a s, e = group_period(node, prefix, suffix) group.period do |p| p.start s p.end e end end |
#metadata_contribution(node, xml) ⇒ Object
190 191 192 193 194 |
# File 'lib/metanorma/itu/front.rb', line 190 def (node, xml) %w(timing).each do |k| a = node.attr(k) and xml.send k, a end end |
#metadata_coverpage_images(node, xml) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/metanorma/itu/front.rb', line 216 def (node, xml) %w(coverpage-image).each do |n| if a = node.attr(n) xml.send n do |c| a.split(",").each do |x| c.image src: x end end end end end |
#metadata_ext(node, xml) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/metanorma/itu/front.rb', line 228 def (node, xml) (node, xml) (node, xml) (node, xml) (node, xml) (node, xml) (node, xml) (node, xml) (node, xml) structured_id(node, xml) (node, xml) end |
#metadata_id(node, xml) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/metanorma/itu/front_id.rb', line 4 def (node, xml) provisional_id(node, xml) td_id(node, xml) itu_id(node, xml) recommendation_id(node, xml) end |
#metadata_ip_notice(node, xml) ⇒ Object
171 172 173 |
# File 'lib/metanorma/itu/front.rb', line 171 def (node, xml) xml.ip_notice_received (node.attr("ip-notice-received") || "false") end |
#metadata_keywords(node, xml) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/metanorma/itu/converter.rb', line 109 def (node, xml) return unless node.attr("keywords") node.attr("keywords").split(/, */).sort.each_with_index do |kw, i| kw_out = i.zero? ? Metanorma::Utils.strict_capitalize_first(kw) : kw xml.keyword kw_out end end |
#metadata_meeting(mtg, acronym, xml) ⇒ Object
184 185 186 187 188 |
# File 'lib/metanorma/itu/front.rb', line 184 def (mtg, acronym, xml) xml.meeting **attr_code(acronym: acronym) do |m| m << mtg end end |
#metadata_meeting_date(val, xml) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/metanorma/itu/front.rb', line 196 def (val, xml) xml.meeting_date do |m| d = val.split("/") if d.size > 1 m.from d[0] m.to d[1] else m.on d[0] end end end |
#metadata_question(node, xml) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/metanorma/itu/front.rb', line 105 def (node, xml) vals = csv_split(node.attr("question"), ",").map do |s1| t, v = s1.split(":", 2).map(&:strip) { id: t, value: v } end vals.each do |v| xml.question do |q| a = v[:id] and q.identifier a a = v[:value] and q.name a end end end |
#metadata_recommendationstatus(node, xml) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/metanorma/itu/front.rb', line 158 def (node, xml) node.attr("recommendation-from") || node.attr("approval-process") or return xml.recommendationstatus do |s| a = node.attr("recommendation-from") and s.from a a = node.attr("recommendation-to") and s.to a node.attr("approval-process") and s.approvalstage **{ process: node.attr("approval-process") } do |x| x << node.attr("approval-status") end end end |
#metadata_sector(node, xml) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/metanorma/itu/front.rb', line 98 def (node, xml) s = node.attr("sector") or return xml.editorialgroup do |a| a.sector { |x| x << s } end end |
#metadata_series(node, xml) ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/metanorma/itu/front.rb', line 148 def (node, xml) { series: "main", series1: "secondary", series2: "tertiary" } .each do |k, v| node.attr(k.to_s) and xml.series **{ type: v } do |s| s.title node.attr(k.to_s) end end end |
#metadata_status(node, xml) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/metanorma/itu/front.rb', line 7 def (node, xml) stage = node.attr("status") || node.attr("docstage") || "published" stage = "draft" if node.attributes.has_key?("draft") xml.status do |s| s.stage stage end end |
#metadata_techreport(node, xml) ⇒ Object
175 176 177 178 179 180 181 182 |
# File 'lib/metanorma/itu/front.rb', line 175 def (node, xml) a = node.attr("meeting") and (a, node.attr("meeting-acronym"), xml) a = node.attr("meeting-place") and xml.meeting_place a a = node.attr("meeting-date") and (a, xml) a = node.attr("intended-type") and xml.intended_type a a = node.attr("source") and xml.source a end |
#numbers_validate(xmldoc) ⇒ Object
Editing Guidelines 9.4.3 Supplanted by rendering
72 |
# File 'lib/metanorma/itu/validate.rb', line 72 def numbers_validate(xmldoc); end |
#olist(node) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/metanorma/itu/converter.rb', line 43 def olist(node) id = Metanorma::Utils::anchor_or_uuid(node) noko do |xml| xml.ol **attr_code(id: id, class: node.attr("class")) do |xml_ol| (node, xml_ol) node.items.each { |item| li(xml_ol, item) } end end end |
#org_abbrev ⇒ Object
70 71 72 73 74 |
# File 'lib/metanorma/itu/front.rb', line 70 def org_abbrev if @i18n.get["ITU"] { @i18n.international_telecommunication_union => @i18n.get["ITU"] } else {} end end |
#other_title_defaultlang(node, xml, type) ⇒ Object
53 54 55 56 |
# File 'lib/metanorma/itu/front.rb', line 53 def other_title_defaultlang(node, xml, type) a = node.attr(type) || node.attr("#{type}-#{@lang}") insert_title(xml, type.sub(/-title/, ""), @lang, a) end |
#other_title_otherlangs(node, xml, type) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/metanorma/itu/front.rb', line 58 def other_title_otherlangs(node, xml, type) node.attributes.each do |k, v| m = /^#{type}-(?<lang>.+)$/.match(k) or next m[:lang] == @lang and next insert_title(xml, type.sub(/-title/, ""), m[:lang], v) end end |
#outputs(node, ret) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/metanorma/itu/converter.rb', line 53 def outputs(node, ret) File.open("#{@filename}.xml", "w:UTF-8") { |f| f.write(ret) } presentation_xml_converter(node).convert("#{@filename}.xml") html_converter(node).convert("#{@filename}.presentation.xml", nil, false, "#{@filename}.html") doc_converter(node).convert("#{@filename}.presentation.xml", nil, false, "#{@filename}.doc") node.attr("no-pdf") or pdf_converter(node)&.convert("#{@filename}.presentation.xml", nil, false, "#{@filename}.pdf") end |
#pdf_converter(node) ⇒ Object
153 154 155 |
# File 'lib/metanorma/itu/converter.rb', line 153 def pdf_converter(node) IsoDoc::ITU::PdfConvert.new(pdf_extract_attributes(node)) end |
#personal_role(node, contrib, suffix) ⇒ Object
208 209 210 211 212 213 214 |
# File 'lib/metanorma/itu/front.rb', line 208 def personal_role(node, contrib, suffix) if node.attr("role#{suffix}")&.downcase == "rapporteur" contrib.role "raporteur", **{ type: "editor" } else super end end |
#presentation_xml_converter(node) ⇒ Object
142 143 144 145 146 147 |
# File 'lib/metanorma/itu/converter.rb', line 142 def presentation_xml_converter(node) IsoDoc::ITU::PresentationXMLConvert .new(html_extract_attributes(node) .merge(output_formats: ::Metanorma::ITU::Processor.new .output_formats)) end |
#provisional_id(node, xml) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/metanorma/itu/front_id.rb', line 11 def provisional_id(node, xml) node.attr("provisional-name") or return xml.docidentifier type: "ITU-provisional" do |i| i << node.attr("provisional-name") end end |
#pub_class(bib) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/metanorma/itu/cleanup.rb', line 42 def pub_class(bib) return 1 if bib.at("#{PUBLISHER}[abbreviation = 'ITU']") return 1 if bib.at("#{PUBLISHER}[name = 'International " \ "Telecommunication Union']") return 2 if bib.at("#{PUBLISHER}[abbreviation = 'ISO']") return 2 if bib.at("#{PUBLISHER}[name = 'International Organization " \ "for Standardization']") return 3 if bib.at("#{PUBLISHER}[abbreviation = 'IEC']") return 3 if bib.at("#{PUBLISHER}[name = 'International " \ "Electrotechnical Commission']") return 4 if bib.at("./docidentifier[@type][not(#{skip_docid} or " \ "@type = 'metanorma')]") 5 end |
#recommendation_id(node, xml) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/metanorma/itu/front_id.rb', line 61 def recommendation_id(node, xml) return unless node.attr("recommendationnumber") node.attr("recommendationnumber").split("/").each do |s| xml.docidentifier type: "ITU-Recommendation" do |i| i << s end end end |
#relaton_relations ⇒ Object
15 16 17 |
# File 'lib/metanorma/itu/front.rb', line 15 def relaton_relations super + %w(complements) end |
#reqt_validate(xmldoc) ⇒ Object
Editing Guidelines 7
60 61 62 63 64 65 66 67 68 |
# File 'lib/metanorma/itu/validate.rb', line 60 def reqt_validate(xmldoc) xmldoc.xpath("//preface/*").each do |c| extract_text(c).split(/\.\s+/).each do |t| /\b(shall|must)\b/i.match(t) and @log.add("Style", c, "Requirement possibly in preface: #{t.strip}") end end end |
#resolution_inline_header(xml) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 11 def resolution_inline_header(xml) @doctype == "resolution" or return xml.xpath("//clause//clause").each do |c| (title = c.at("./title")) && !title.text&.empty? and next c["inline-header"] = true end end |
#section_check(xmldoc) ⇒ Object
Editing Guidelines 7.2, 7.3
122 123 124 125 126 127 |
# File 'lib/metanorma/itu/validate.rb', line 122 def section_check(xmldoc) xmldoc.at("//bibdata/abstract") or @log.add("Style", nil, "No Summary has been provided") xmldoc.at("//bibdata/keyword") or @log.add("Style", nil, "No Keywords have been provided") end |
#section_names_terms_cleanup(xml) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 120 def section_names_terms_cleanup(xml) super replace_title( xml, "//terms[@type = 'internal'] | " \ "//clause[./terms[@type = 'internal']]" \ "[not(./terms[@type = 'external'])]", @i18n&.internal_termsdef ) replace_title( xml, "//terms[@type = 'external'] | " \ "//clause[./terms[@type = 'external']]" \ "[not(./terms[@type = 'internal'])]", @i18n&.external_termsdef ) end |
#section_validate(doc) ⇒ Object
106 107 108 109 110 |
# File 'lib/metanorma/itu/validate.rb', line 106 def section_validate(doc) super section_check(doc.root) unnumbered_check(doc.root) end |
#sections_cleanup(xml) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 4 def sections_cleanup(xml) super insert_missing_sections(xml) unless @no_insert_missing_sections insert_empty_clauses(xml) resolution_inline_header(xml) end |
#sections_names_pref_cleanup(xml) ⇒ Object
142 143 144 145 146 147 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 142 def sections_names_pref_cleanup(xml) super t = xml.at("//preface//abstract") or return t["id"] == "_summary" and replace_title(xml, "//preface//abstract", @i18n&.summary) end |
#sectiontype(node, level = true) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/metanorma/itu/converter.rb', line 87 def sectiontype(node, level = true) ret = super hdr = sectiontype_streamline(node.attr("heading")&.downcase) return nil if ret == "terms and definitions" && hdr != "terms and definitions" && node.level > 1 return nil if ret == "symbols and abbreviated terms" && hdr != "symbols and abbreviated terms" && node.level > 1 ret end |
#sectiontype_streamline(ret) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/metanorma/itu/converter.rb', line 75 def sectiontype_streamline(ret) case ret when "definitions", "terms defined elsewhere", "terms defined in this recommendation" "terms and definitions" when "abbreviations and acronyms" then "symbols and abbreviated terms" when "references" then "normative references" else super end end |
#smartquotes_cleanup(xmldoc) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/metanorma/itu/cleanup.rb', line 28 def smartquotes_cleanup(xmldoc) @smartquotes and return super xmldoc.traverse do |n| n.text? or next n.replace(HTMLEntities.new.encode( n.text.gsub(/\u2019|\u2018|\u201a|\u201b/, "'") .gsub(/\u201c|\u201d|\u201e|\u201f/, '"'), :basic )) end xmldoc end |
#sort_biblio(bib) ⇒ Object
58 59 60 61 62 |
# File 'lib/metanorma/itu/cleanup.rb', line 58 def sort_biblio(bib) bib.sort do |a, b| sort_biblio_key(a) <=> sort_biblio_key(b) end end |
#sort_biblio_key(bib) ⇒ Object
sort by: doc class (ITU, ISO, IEC, other standard (not DOI &c), other then standard class (docid class other than DOI &c) then alphanumeric doc id (not DOI &c) then title
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/metanorma/itu/cleanup.rb', line 68 def sort_biblio_key(bib) pubclass = pub_class(bib) id = bib&.at("./docidentifier[not(#{skip_docid} or @type = " \ "'metanorma')]") = bib&.at("./docidentifier[@type = 'metanorma']")&.text abbrid = unless /^\[\d+\]$/.match?() type = id["type"] if id title = bib&.at("./title[@type = 'main']")&.text || bib&.at("./title")&.text || bib&.at("./formattedref")&.text "#{pubclass} :: #{type} :: #{id&.text || } :: #{title}" end |
#stage_validate(xmldoc) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/metanorma/itu/validate.rb', line 19 def stage_validate(xmldoc) stage = xmldoc&.at("//bibdata/status/stage")&.text %w(in-force superseded in-force-prepublished withdrawn draft).include? stage or @log.add("Document Attributes", nil, "#{stage} is not a recognised status") end |
#structured_id(node, xml) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/metanorma/itu/front_id.rb', line 71 def structured_id(node, xml) return unless node.attr("docnumber") xml.structuredidentifier do |i| i.bureau node.attr("bureau") || "T" i.docnumber node.attr("docnumber") a = node.attr("annexid") and i.annexid a a = node.attr("amendment-number") and i.amendment a a = node.attr("corrigendum-number") and i.corrigendum a end end |
#style(_node, _text) ⇒ Object
71 72 73 |
# File 'lib/metanorma/itu/converter.rb', line 71 def style(_node, _text) nil end |
#style_two_regex_not_prev(node, text, regex, regex_prev, warning) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/metanorma/itu/validate.rb', line 74 def style_two_regex_not_prev(node, text, regex, regex_prev, warning) text.nil? and return arr = text.split(/\W+/) arr.each_index do |i| m = regex.match arr[i] m_prev = i.zero? ? nil : regex_prev.match(arr[i - 1]) if !m.nil? && m_prev.nil? @log.add("Style", node, "#{warning}: #{m[:num]}") end end end |
#symbols_cleanup(xmldoc) ⇒ Object
136 137 138 139 140 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 136 def symbols_cleanup(xmldoc) sym = xmldoc.at("//definitions/title") sym and sym&.next_element&.name == "dl" and sym.next = "<p>#{@i18n.symbols_boilerplate}</p>" end |
#table_cleanup(xmldoc) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/metanorma/itu/cleanup.rb', line 6 def table_cleanup(xmldoc) super xmldoc.xpath("//thead/tr[1]/th | //thead/tr[1]/td").each do |t| text = t.at("./descendant::text()") or next text.replace(text.text.capitalize) end end |
#td_id(node, xml) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/metanorma/itu/front_id.rb', line 18 def td_id(node, xml) node.attr("td-number") or return xml.docidentifier type: "ITU-TemporaryDocument" do |i| i << node.attr("td-number") end end |
#term_def_subclause_parse(attrs, xml, node) ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/metanorma/itu/converter.rb', line 98 def term_def_subclause_parse(attrs, xml, node) case sectiontype1(node) when "terms defined in this recommendation" term_def_parse(attrs.merge(type: "internal"), xml, node, false) when "terms defined elsewhere" term_def_parse(attrs.merge(type: "external"), xml, node, false) else super end end |
#term_defs_boilerplate(div, _source, _term, _preface, _isodoc) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 105 def term_defs_boilerplate(div, _source, _term, _preface, _isodoc) internal, external = terms_extract(div.parent) internal&.next_element&.name == "term" and internal.next = "<p>#{@i18n.internal_terms_boilerplate}</p>" internal and internal&.next_element == nil and internal.next = "<p>#{@i18n.no_terms_boilerplate}</p>" external&.next_element&.name == "term" and external.next = "<p>#{@i18n.external_terms_boilerplate}</p>" external and external&.next_element == nil and external.next = "<p>#{@i18n.no_terms_boilerplate}</p>" !internal and !external and %w(term terms).include? div&.next_element&.name and div.next = "<p>#{@i18n.term_def_boilerplate}</p>" end |
#termdef_boilerplate_cleanup(xmldoc) ⇒ Object
97 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 97 def termdef_boilerplate_cleanup(xmldoc); end |
#termdef_style(xmldoc) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/metanorma/itu/validate.rb', line 129 def termdef_style(xmldoc) xmldoc.xpath("//term").each do |t| para = t.at("./definition/verbal-definition") || return term = t.at("./preferred//name").text termdef_warn(term, /^[A-Z][a-z]+/, t, term, "term is not lowercase") termdef_warn(para.text, /^[a-z]/, t, term, "term definition does not start with capital") termdef_warn(para.text, /[^.]$/, t, term, "term definition does not end with period") end end |
#termdef_warn(text, regex, node, term, msg) ⇒ Object
141 142 143 |
# File 'lib/metanorma/itu/validate.rb', line 141 def termdef_warn(text, regex, node, term, msg) regex.match(text) && @log.add("Style", node, "#{term}: #{msg}") end |
#terms_extract(div) ⇒ Object
99 100 101 102 103 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 99 def terms_extract(div) internal = div.at("./terms[@type = 'internal']/title") external = div.at("./terms[@type = 'external']/title") [internal, external] end |
#title(node, xml) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/metanorma/itu/front.rb', line 43 def title(node, xml) title_defaultlang(node, xml) title_otherlangs(node, xml) %w(subtitle amendment-title corrigendum-title collection-title slogan-title).each do |t| other_title_defaultlang(node, xml, t) other_title_otherlangs(node, xml, t) end end |
#title_defaultlang(node, xml) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/metanorma/itu/front.rb', line 26 def title_defaultlang(node, xml) a = node.attr("title") || node.attr("title-#{@lang}") || node.title insert_title(xml, "main", @lang, a) if a = node.attr("annextitle") || node.attr("annextitle-#{@lang}") insert_title(xml, "annex", @lang, a) end end |
#title_otherlangs(node, xml) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/metanorma/itu/front.rb', line 34 def title_otherlangs(node, xml) node.attributes.each do |k, v| /^(?:annex)?title-(?<lang>.+)$/ =~ k or next lang == @lang and next type = /^annex/.match?(k) ? "annex" : "main" insert_title(xml, type, lang, v) end end |
#title_validate(_root) ⇒ Object
17 18 19 |
# File 'lib/metanorma/itu/converter.rb', line 17 def title_validate(_root) nil end |
#title_validate1(xmldoc) ⇒ Object
Editing Guidelines 6.3
39 40 41 42 43 44 45 46 47 |
# File 'lib/metanorma/itu/validate.rb', line 39 def title_validate1(xmldoc) t = xmldoc.at("//bibdata/title")&.text xmldoc.xpath("//bibdata/series/title").each do |s| series = s.text.sub(/^[A-Z]: /, "") t.downcase.include?(series.downcase) and @log.add("Document Attributes", nil, "Title includes series name #{series}") end end |
#unnumbered_check(xmldoc) ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/metanorma/itu/validate.rb', line 112 def unnumbered_check(xmldoc) xmldoc.xpath("//clause[@unnumbered = 'true']").each do |c| next if (@doctype == "resolution") && (c.parent.name == "sections") && !c.at("./preceding-sibling::clause") @log.add("Style", c, "Unnumbered clause out of place") end end |
#validate(doc) ⇒ Object
65 66 67 68 69 |
# File 'lib/metanorma/itu/converter.rb', line 65 def validate(doc) content_validate(doc) schema_validate(formattedstr_strip(doc.dup), File.join(File.dirname(__FILE__), "itu.rng")) end |