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/front_contrib.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
Instance Method Summary collapse
- #abstract_parse(attrs, xml, node) ⇒ Object
- #approval_validate(xmldoc) ⇒ Object
- #bibdata_validate(doc) ⇒ Object
- #biblio_reorder(xmldoc) ⇒ Object
- #boilerplate_file(_xmldoc) ⇒ Object
- #clause_parse(attrs, xml, node) ⇒ Object
- #cleanup(xmldoc) ⇒ Object
- #committee_contributors(node, xml, agency, opt) ⇒ Object
- #content_validate(doc) ⇒ Object
- #default_publisher ⇒ Object
- #doc_converter(node) ⇒ Object
- #doc_extract_attributes(node) ⇒ Object
- #doctype_validate(_xmldoc) ⇒ Object
- #document_scheme(node) ⇒ Object
- #extract_org_attrs_complex(node, opts, source, suffix) ⇒ Object
- #extract_text(node) ⇒ Object
- #full_committee_id(contrib) ⇒ Object
- #group_period(node, prefix, suffix) ⇒ Object
- #header_rows_cleanup(xmldoc) ⇒ Object
- #html_converter(node) ⇒ Object
- #html_extract_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
- #iso_id(node, xml) ⇒ 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
- #metadata_committee_prep(node) ⇒ Object
- #metadata_committee_types(_node) ⇒ Object
- #metadata_contribution(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_series(node, xml) ⇒ Object
- #metadata_status(node, xml) ⇒ Object
- #metadata_studyperiod(node, xml) ⇒ Object
- #metadata_techreport(node, xml) ⇒ Object
-
#numbers_validate(xmldoc) ⇒ Object
Editing Guidelines 9.4.3 Supplanted by rendering.
- #ol_attrs(node) ⇒ Object
- #org_abbrev ⇒ Object
- #org_attrs_add_committees(node, ret, opts, opts_orig) ⇒ 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
- #published?(status, _xmldoc) ⇒ Boolean
- #recommendation_id(node, xml) ⇒ Object
- #relaton_relations ⇒ Object
-
#reqt_validate(xmldoc) ⇒ Object
Editing Guidelines 7.
- #resolution_inline_header(xml) ⇒ Object
- #schema_file ⇒ 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
Instance Method Details
#abstract_parse(attrs, xml, node) ⇒ Object
113 114 115 116 117 118 |
# File 'lib/metanorma/itu/converter.rb', line 113 def abstract_parse(attrs, xml, node) xml.abstract **attr_code(attrs) do |xml_section| xml_section.title { |name| name << node.title } xml_section << node.content end end |
#approval_validate(xmldoc) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/metanorma/itu/validate.rb', line 85 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_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
26 27 28 |
# File 'lib/metanorma/itu/converter.rb', line 26 def boilerplate_file(_xmldoc) File.join(@libdir, "boilerplate.adoc") end |
#clause_parse(attrs, xml, node) ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'lib/metanorma/itu/converter.rb', line 103 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 |
#committee_contributors(node, xml, agency, opt) ⇒ Object
14 15 16 17 |
# File 'lib/metanorma/itu/front_contrib.rb', line 14 def committee_contributors(node, xml, agency, opt) (node) or return super 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 |
#default_publisher ⇒ Object
4 5 6 |
# File 'lib/metanorma/itu/front_contrib.rb', line 4 def default_publisher @i18n.get["ITU"] || @i18n.international_telecommunication_union end |
#doc_converter(node) ⇒ Object
149 150 151 |
# File 'lib/metanorma/itu/converter.rb', line 149 def doc_converter(node) IsoDoc::Itu::WordConvert.new(doc_extract_attributes(node)) end |
#doc_extract_attributes(node) ⇒ Object
129 130 131 132 |
# File 'lib/metanorma/itu/converter.rb', line 129 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
120 121 122 |
# File 'lib/metanorma/itu/converter.rb', line 120 def document_scheme(node) super || "current" end |
#extract_org_attrs_complex(node, opts, source, suffix) ⇒ Object
23 24 25 |
# File 'lib/metanorma/itu/front_contrib.rb', line 23 def extract_org_attrs_complex(node, opts, source, suffix) super.merge(ident: node.attr("#{source}-acronym#{suffix}")).compact 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 |
#full_committee_id(contrib) ⇒ Object
27 |
# File 'lib/metanorma/itu/front_contrib.rb', line 27 def full_committee_id(contrib); end |
#group_period(node, prefix, suffix) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/metanorma/itu/front.rb', line 74 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
141 142 143 |
# File 'lib/metanorma/itu/converter.rb', line 141 def html_converter(node) IsoDoc::Itu::HtmlConvert.new(html_extract_attributes(node)) end |
#html_extract_attributes(node) ⇒ Object
124 125 126 127 |
# File 'lib/metanorma/itu/converter.rb', line 124 def html_extract_attributes(node) super.merge(hierarchicalassets: node.attr("hierarchical-object-numbering")) end |
#init(node) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/metanorma/itu/converter.rb', line 18 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
30 31 32 33 |
# File 'lib/metanorma/itu/converter.rb', line 30 def init_misc(node) super @default_doctype = "recommendation" end |
#insert_conventions(xml) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 75 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_text} type='conventions'>\n <title \#{add_id_text}>\#{@i18n.conventions}</title>\n <p>\#{@i18n.clause_empty}</p></clause>\n XML\n end\nend\n" |
#insert_empty_clauses(xml) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 87 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
96 97 98 99 100 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 96 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
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 43 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_text} normative='true'>\n <title \#{add_id_text}>\#{@i18n.normref}</title></references>\n XML\n xml.at(\"//sentinel\")&.remove\nend\n" |
#insert_scope(xml) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 29 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_text}><title \#{add_id_text}>\#{@i18n.scope}</title>\n <p>\#{@i18n.clause_empty}</p></clause>\n XML\n xml.at(\"//sentinel\")&.remove\nend\n" |
#insert_symbols(xml) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 64 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_text}>\n <title \#{add_id_text}>\#{@i18n.symbolsabbrev}</title></definitions>\n XML\n end\nend\n" |
#insert_terms(xml) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 56 def insert_terms(xml) ins = xml.at("//sections/clause[@type = 'scope']") xml.at("//sections//terms") or ins.next = " <terms \#{add_id_text}><title \#{add_id_text}>\#{@i18n.termsdef}</title></terms>\n XML\nend\n" |
#iso_id(node, xml) ⇒ Object
26 27 28 29 |
# File 'lib/metanorma/itu/front_id.rb', line 26 def iso_id(node, xml) a = node.attr("common-text-docnumber") and xml.docidentifier a, type: "ISO" end |
#itu_contrib_id(node) ⇒ Object
51 52 53 54 55 |
# File 'lib/metanorma/itu/front_id.rb', line 51 def itu_contrib_id(node) group = node.attr("group-acronym") || node.attr("group")&.sub("Study Group ", "SG") || "XXX" "#{group}-C#{node.attr('docnumber')}" end |
#itu_id(node, xml) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/metanorma/itu/front_id.rb', line 57 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
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/metanorma/itu/front_id.rb', line 34 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
97 98 99 100 101 102 103 104 |
# File 'lib/metanorma/itu/validate.rb', line 97 def itu_identifier_validate(xmldoc) xmldoc.xpath("//bibdata/docidentifier[@type = 'ITU']").each do |x| /^SG \d+/.match?(x.text) || /^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
47 48 49 |
# File 'lib/metanorma/itu/front_id.rb', line 47 def itu_service_pub_id(node) @i18n.annex_to_itu_ob_abbrev.sub(/%/, node.attr("docnumber")) end |
#metadata_committee_prep(node) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/metanorma/itu/front_contrib.rb', line 29 def (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 |
#metadata_committee_types(_node) ⇒ Object
19 20 21 |
# File 'lib/metanorma/itu/front_contrib.rb', line 19 def (_node) %w(bureau sector group subgroup workgroup) end |
#metadata_contribution(node, xml) ⇒ Object
123 124 125 126 127 |
# File 'lib/metanorma/itu/front.rb', line 123 def (node, xml) %w(timing).each do |k| a = node.attr(k) and xml.send k, a end end |
#metadata_ext(node, xml) ⇒ Object
157 158 159 160 161 162 163 164 165 |
# File 'lib/metanorma/itu/front.rb', line 157 def (node, xml) super (node, xml) (node, xml) (node, xml) (node, xml) (node, xml) (node, xml) end |
#metadata_id(node, xml) ⇒ Object
4 5 6 7 8 9 10 |
# 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) iso_id(node, xml) end |
#metadata_ip_notice(node, xml) ⇒ Object
104 105 106 |
# File 'lib/metanorma/itu/front.rb', line 104 def (node, xml) xml.ip_notice_received (node.attr("ip-notice-received") || "false") end |
#metadata_keywords(node, xml) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/metanorma/itu/converter.rb', line 95 def (node, xml) node.attr("keywords") or return 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
117 118 119 120 121 |
# File 'lib/metanorma/itu/front.rb', line 117 def (mtg, acronym, xml) xml.meeting **attr_code(acronym: acronym) do |m| m << mtg end end |
#metadata_meeting_date(val, xml) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/metanorma/itu/front.rb', line 129 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
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/metanorma/itu/front.rb', line 61 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
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/metanorma/itu/front.rb', line 91 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_series(node, xml) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/metanorma/itu/front.rb', line 81 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
8 9 10 11 12 13 14 |
# File 'lib/metanorma/itu/front.rb', line 8 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_studyperiod(node, xml) ⇒ Object
149 150 151 152 153 154 155 |
# File 'lib/metanorma/itu/front.rb', line 149 def (node, xml) s, e = group_period(node, "", "") xml.studyperiod do |p| p.start s p.end e end end |
#metadata_techreport(node, xml) ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/metanorma/itu/front.rb', line 108 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 |
#ol_attrs(node) ⇒ Object
35 36 37 38 39 |
# File 'lib/metanorma/itu/converter.rb', line 35 def ol_attrs(node) ret = super ret.delete(:type) ret.merge(class: node.attr("class")) end |
#org_abbrev ⇒ Object
8 9 10 11 12 |
# File 'lib/metanorma/itu/front_contrib.rb', line 8 def org_abbrev if @i18n.get["ITU"] { @i18n.international_telecommunication_union => @i18n.get["ITU"] } else {} end end |
#org_attrs_add_committees(node, ret, opts, opts_orig) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/metanorma/itu/front_contrib.rb', line 39 def org_attrs_add_committees(node, ret, opts, opts_orig) opts_orig[:groups]&.each_with_index do |g, i| i.zero? and next contributors_committees_pad_multiples(ret.first, node, g) opts = committee_contrib_org_prep(node, g, nil, opts_orig) ret << org_attrs_parse_core(node, opts).map do |x| x.merge(subdivtype: opts[:subdivtype]) end end contributors_committees_nest1(ret) end |
#other_title_defaultlang(node, xml, type) ⇒ Object
48 49 50 51 |
# File 'lib/metanorma/itu/front.rb', line 48 def other_title_defaultlang(node, xml, type) a = node.attr(type) || node.attr("#{type}-#{@lang}") add_title_xml(xml, a, @lang, type.sub(/-title/, "")) end |
#other_title_otherlangs(node, xml, type) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/metanorma/itu/front.rb', line 53 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 add_title_xml(xml, v, m[:lang], type.sub(/-title/, "")) end end |
#outputs(node, ret) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/metanorma/itu/converter.rb', line 41 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
145 146 147 |
# File 'lib/metanorma/itu/converter.rb', line 145 def pdf_converter(node) IsoDoc::Itu::PdfConvert.new(pdf_extract_attributes(node)) end |
#personal_role(node, contrib, suffix) ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/metanorma/itu/front.rb', line 141 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
134 135 136 137 138 139 |
# File 'lib/metanorma/itu/converter.rb', line 134 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
12 13 14 15 16 17 |
# File 'lib/metanorma/itu/front_id.rb', line 12 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 |
#published?(status, _xmldoc) ⇒ Boolean
86 87 88 |
# File 'lib/metanorma/itu/cleanup.rb', line 86 def published?(status, _xmldoc) !%w(in-force-prepublished draft).include?(status.downcase) end |
#recommendation_id(node, xml) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/metanorma/itu/front_id.rb', line 67 def recommendation_id(node, xml) node.attr("recommendationnumber") or return node.attr("recommendationnumber").split("/").each do |s| xml.docidentifier type: "ITU-Recommendation" do |i| i << s end end end |
#relaton_relations ⇒ Object
16 17 18 |
# File 'lib/metanorma/itu/front.rb', line 16 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 |
#schema_file ⇒ Object
53 54 55 |
# File 'lib/metanorma/itu/converter.rb', line 53 def schema_file "itu.rng" 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
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 125 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
147 148 149 150 151 152 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 147 def sections_names_pref_cleanup(xml) t = xml.at("//preface//abstract/title") t&.text&.downcase == "summary" and summary = true super summary and replace_title(xml, "//preface//abstract", @i18n&.summary) end |
#sectiontype(node, level = true) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/metanorma/itu/converter.rb', line 73 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
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/metanorma/itu/converter.rb', line 61 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 = metaid unless /^\[\d+\]$/.match?(metaid) type = id["type"] if id title = bib.at("./title[@type = 'main']")&.text || bib.at("./title")&.text || bib.at("./formattedref")&.text "#{pubclass} :: #{type} :: #{id&.text || metaid} :: #{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
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/metanorma/itu/front_id.rb', line 76 def structured_id(node, xml) node.attr("docnumber") or return 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
57 58 59 |
# File 'lib/metanorma/itu/converter.rb', line 57 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 |
# 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_prev = i.zero? ? nil : regex_prev.match(arr[i - 1]) if !regex.match?(arr[i]) && m_prev.nil? @log.add("Style", node, "#{warning}: #{m[:num]}") end end end |
#symbols_cleanup(xmldoc) ⇒ Object
141 142 143 144 145 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 141 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
19 20 21 22 23 24 |
# File 'lib/metanorma/itu/front_id.rb', line 19 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
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/metanorma/itu/converter.rb', line 84 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
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 110 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
102 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 102 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
104 105 106 107 108 |
# File 'lib/metanorma/itu/cleanup_section.rb', line 104 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
38 39 40 41 42 43 44 45 46 |
# File 'lib/metanorma/itu/front.rb', line 38 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
20 21 22 23 24 25 26 27 |
# File 'lib/metanorma/itu/front.rb', line 20 def title_defaultlang(node, xml) a = node.attr("title") || node.attr("title-#{@lang}") || node.attr("doctitle") add_title_xml(xml, a, @lang, "main") if a = node.attr("annextitle") || node.attr("annextitle-#{@lang}") add_title_xml(xml, a, @lang, "annex") end end |
#title_otherlangs(node, xml) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/metanorma/itu/front.rb', line 29 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" add_title_xml(xml, v, lang, type) end end |
#title_validate(_root) ⇒ Object
14 15 16 |
# File 'lib/metanorma/itu/converter.rb', line 14 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 |