Class: Metanorma::Itu::Converter
- Inherits:
-
Standoc::Converter
- Object
- Standoc::Converter
- Metanorma::Itu::Converter
- Defined in:
- lib/metanorma/itu/log.rb,
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
- ITU_LOG_MESSAGES =
{ # rubocop:disable Naming/VariableNumber "ITU_1": { category: "Document Attributes", error: "%s is not a recognised document type", severity: 2 }, "ITU_2": { category: "Document Attributes", error: "%s is not a recognised status", severity: 2 }, "ITU_3": { category: "Document Attributes", error: "Title includes series name %s", severity: 2 }, "ITU_4": { category: "Style", error: "Requirement possibly in preface: %s", severity: 2 }, "ITU_6": { category: "Document Attributes", error: "Recommendation Status %s inconsistent with AAP", severity: 2 }, "ITU_7": { category: "Document Attributes", error: "Recommendation Status %s inconsistent with TAP", severity: 2 }, "ITU_8": { category: "Style", error: "%s does not match ITU document identifier conventions", severity: 2 }, "ITU_9": { category: "Style", error: "Unnumbered clause out of place", severity: 2 }, "ITU_10": { category: "Style", error: "No Summary has been provided", severity: 2 }, "ITU_11": { category: "Style", error: "No Keywords have been provided", severity: 2 }, "ITU_12": { category: "Style", error: "(terms) %s: %s", severity: 2 }, }.freeze
- 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
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) && m_prev.nil? @log.add(“Style”, node, “#warning: #:num”) # ID = ITU_5 end end end.
- #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
-
#log_messages ⇒ Object
rubocop:enable Naming/VariableNumber.
- #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
- #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
114 115 116 117 118 119 120 |
# File 'lib/metanorma/itu/converter.rb', line 114 def abstract_parse(attrs, xml, node) xml.abstract **attr_code(attrs) do |xml_section| # xml_section.title { |name| name << node.title } add_noko_elem(xml_section, "title", node.title) xml_section << node.content end end |
#approval_validate(xmldoc) ⇒ Object
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]}")
# ID = ITU_5
end
end
end
82 83 84 85 86 87 88 89 90 |
# File 'lib/metanorma/itu/validate.rb', line 82 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("ITU_6", nil, params: [s.text]) (process == "tap") && !%w(determined in-force).include?(s.text) and @log.add("ITU_7", nil, params: [s.text]) 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
104 105 106 107 108 109 110 111 112 |
# File 'lib/metanorma/itu/converter.rb', line 104 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
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/metanorma/itu/validate.rb', line 25 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
151 152 153 |
# File 'lib/metanorma/itu/converter.rb', line 151 def doc_converter(node) IsoDoc::Itu::WordConvert.new(doc_extract_attributes(node)) end |
#doc_extract_attributes(node) ⇒ Object
131 132 133 134 |
# File 'lib/metanorma/itu/converter.rb', line 131 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 |
# 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("ITU_1", nil, params: [@doctype]) end |
#document_scheme(node) ⇒ Object
122 123 124 |
# File 'lib/metanorma/itu/converter.rb', line 122 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
46 47 48 49 50 51 52 53 54 |
# File 'lib/metanorma/itu/validate.rb', line 46 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
76 77 78 79 80 81 |
# File 'lib/metanorma/itu/front.rb', line 76 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
143 144 145 |
# File 'lib/metanorma/itu/converter.rb', line 143 def html_converter(node) IsoDoc::Itu::HtmlConvert.new(html_extract_attributes(node)) end |
#html_extract_attributes(node) ⇒ Object
126 127 128 129 |
# File 'lib/metanorma/itu/converter.rb', line 126 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 = <<~XML <clause #{add_id_text} type='conventions'> <title #{add_id_text}>#{@i18n.conventions}</title> <p>#{@i18n.clause_empty}</p></clause> XML end end |
#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 = <<~XML <references #{add_id_text} normative='true'> <title #{add_id_text}>#{@i18n.normref}</title></references> XML xml.at("//sentinel")&.remove end |
#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 = <<~XML <clause type='scope' #{add_id_text}><title #{add_id_text}>#{@i18n.scope}</title> <p>#{@i18n.clause_empty}</p></clause> XML xml.at("//sentinel")&.remove end |
#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 = <<~XML <definitions #{add_id_text}> <title #{add_id_text}>#{@i18n.symbolsabbrev}</title></definitions> XML end end |
#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 = <<~XML <terms #{add_id_text}><title #{add_id_text}>#{@i18n.termsdef}</title></terms> XML end |
#iso_id(node, xml) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/metanorma/itu/front_id.rb', line 30 def iso_id(node, xml) add_noko_elem(xml, "docidentifier", node.attr("common-text-docnumber"), type: "ISO") # a = node.attr("common-text-docnumber") and # xml.docidentifier a, type: "ISO" end |
#itu_contrib_id(node) ⇒ Object
57 58 59 60 61 |
# File 'lib/metanorma/itu/front_id.rb', line 57 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
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/metanorma/itu/front_id.rb', line 63 def itu_id(node, xml) node.attr("docnumber") || node.attr("docidentifier") or return add_noko_elem(xml, "docidentifier", node.attr("docidentifier") || itu_id1(node, false), type: "ITU", primary: "true") # xml.docidentifier type: "ITU", primary: "true" do |i| # i << (node.attr("docidentifier") || itu_id1(node, false)) # end add_noko_elem(xml, "docidentifier", itu_id1(node, true), type: "ITU-lang") # xml.docidentifier type: "ITU-lang" do |i| # i << itu_id1(node, true) # end end |
#itu_id1(node, lang) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/metanorma/itu/front_id.rb', line 40 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
92 93 94 95 96 97 98 |
# File 'lib/metanorma/itu/validate.rb', line 92 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("ITU_8", nil, params: [x.text]) end end |
#itu_service_pub_id(node) ⇒ Object
53 54 55 |
# File 'lib/metanorma/itu/front_id.rb', line 53 def itu_service_pub_id(node) @i18n.annex_to_itu_ob_abbrev.sub(/%/, node.attr("docnumber")) end |
#log_messages ⇒ Object
rubocop:enable Naming/VariableNumber
42 43 44 |
# File 'lib/metanorma/itu/log.rb', line 42 def super.merge(ITU_LOG_MESSAGES) 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
133 134 135 136 137 138 |
# File 'lib/metanorma/itu/front.rb', line 133 def (node, xml) %w(timing).each do |k| add_noko_elem(xml, k, node.attr(k)) # a = node.attr(k) and xml.send k, a end end |
#metadata_ext(node, xml) ⇒ Object
172 173 174 175 176 177 178 179 180 |
# File 'lib/metanorma/itu/front.rb', line 172 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
108 109 110 111 112 |
# File 'lib/metanorma/itu/front.rb', line 108 def (node, xml) add_noko_elem(xml, "ip-notice-received", node.attr("ip-notice-received") || "false") # xml.ip_notice_received (node.attr("ip-notice-received") || "false") end |
#metadata_keywords(node, xml) ⇒ Object
95 96 97 98 99 100 101 102 |
# 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 add_noko_elem(xml, "keyword", kw_out) # xml.keyword kw_out end end |
#metadata_meeting(mtg, acronym, xml) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/metanorma/itu/front.rb', line 126 def (mtg, acronym, xml) add_noko_elem(xml, "meeting", mtg, acronym: acronym) # xml.meeting **attr_code(acronym: acronym) do |m| # m << mtg # end end |
#metadata_meeting_date(val, xml) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/metanorma/itu/front.rb', line 140 def (val, xml) xml.meeting_date do |m| d = val.split("/") if d.size > 1 add_noko_elem(m, "from", d[0]) # m.from d[0] add_noko_elem(m, "to", d[1]) # m.to d[1] else add_noko_elem(m, "on", d[0]) # m.on d[0] end end end |
#metadata_question(node, xml) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/metanorma/itu/front.rb', line 62 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| add_noko_elem(q, "identifier", v[:id]) # q.identifier a add_noko_elem(q, "name", v[:value]) # q.name a end end end |
#metadata_recommendationstatus(node, xml) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/metanorma/itu/front.rb', line 93 def (node, xml) node.attr("recommendation-from") || node.attr("approval-process") or return xml.recommendationstatus do |s| add_noko_elem(s, "from", node.attr("recommendation-from")) add_noko_elem(s, "to", node.attr("recommendation-to")) node.attr("approval-process") and add_noko_elem(s, "approvalstage", node.attr("approval-status"), process: node.attr("approval-process")) # s.approvalstage **{ process: node.attr("approval-process") } do |x| # x << node.attr("approval-status") # end end end |
#metadata_series(node, xml) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/metanorma/itu/front.rb', line 83 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| add_noko_elem(s, "title", node.attr(k.to_s)) end end end |
#metadata_status(node, xml) ⇒ Object
8 9 10 11 12 13 14 15 |
# 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| add_noko_elem(s, "stage", stage) # s.stage stage end end |
#metadata_studyperiod(node, xml) ⇒ Object
164 165 166 167 168 169 170 |
# File 'lib/metanorma/itu/front.rb', line 164 def (node, xml) s, e = group_period(node, "", "") xml.studyperiod do |p| add_noko_elem(p, "start", s.to_s) add_noko_elem(p, "end", e.to_s) end end |
#metadata_techreport(node, xml) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/metanorma/itu/front.rb', line 114 def (node, xml) a = node.attr("meeting") and (a, node.attr("meeting-acronym"), xml) add_noko_elem(xml, "meeting_place", node.attr("meeting-place")) # a = node.attr("meeting-place") and xml.meeting_place a a = node.attr("meeting-date") and (a, xml) add_noko_elem(xml, "intended_type", node.attr("intended-type")) # a = node.attr("intended-type") and xml.intended_type a add_noko_elem(xml, "source", node.attr("source")) # a = node.attr("source") and xml.source a end |
#numbers_validate(xmldoc) ⇒ Object
Editing Guidelines 9.4.3 Supplanted by rendering
68 |
# File 'lib/metanorma/itu/validate.rb', line 68 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
49 50 51 52 |
# File 'lib/metanorma/itu/front.rb', line 49 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
54 55 56 57 58 59 60 |
# File 'lib/metanorma/itu/front.rb', line 54 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
147 148 149 |
# File 'lib/metanorma/itu/converter.rb', line 147 def pdf_converter(node) IsoDoc::Itu::PdfConvert.new(pdf_extract_attributes(node)) end |
#personal_role(node, contrib, suffix) ⇒ Object
155 156 157 158 159 160 161 162 |
# File 'lib/metanorma/itu/front.rb', line 155 def personal_role(node, contrib, suffix) if node.attr("role#{suffix}")&.downcase == "rapporteur" add_noko_elem(contrib, "role", "raporteur", type: "editor") # contrib.role "raporteur", **{ type: "editor" } else super end end |
#presentation_xml_converter(node) ⇒ Object
136 137 138 139 140 141 |
# File 'lib/metanorma/itu/converter.rb', line 136 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 18 19 |
# File 'lib/metanorma/itu/front_id.rb', line 12 def provisional_id(node, xml) node.attr("provisional-name") or return add_noko_elem(xml, "docidentifier", node.attr("provisional-name"), type: "ITU-provisional") # 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
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/metanorma/itu/front_id.rb', line 77 def recommendation_id(node, xml) node.attr("recommendationnumber") or return node.attr("recommendationnumber").split("/").each do |s| add_noko_elem(xml, "docidentifier", s, type: "ITU-Recommendation") # xml.docidentifier type: "ITU-Recommendation" do |i| # i << s # end end end |
#relaton_relations ⇒ Object
17 18 19 |
# File 'lib/metanorma/itu/front.rb', line 17 def relaton_relations super + %w(complements) end |
#reqt_validate(xmldoc) ⇒ Object
Editing Guidelines 7
57 58 59 60 61 62 63 64 |
# File 'lib/metanorma/itu/validate.rb', line 57 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("ITU_4", c, params: [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
116 117 118 119 120 121 |
# File 'lib/metanorma/itu/validate.rb', line 116 def section_check(xmldoc) xmldoc.at("//bibdata/abstract") or @log.add("ITU_10", nil) xmldoc.at("//bibdata/keyword") or @log.add("ITU_11", nil) 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
100 101 102 103 104 |
# File 'lib/metanorma/itu/validate.rb', line 100 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 || } :: #{title}" end |
#stage_validate(xmldoc) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/metanorma/itu/validate.rb', line 18 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("ITU_2", nil, params: [stage]) end |
#structured_id(node, xml) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/metanorma/itu/front_id.rb', line 88 def structured_id(node, xml) node.attr("docnumber") or return xml.structuredidentifier do |i| add_noko_elem(i, "bureau", node.attr("bureau") || "T") # i.bureau node.attr("bureau") || "T" add_noko_elem(i, "docnumber", node.attr("docnumber")) # i.docnumber node.attr("docnumber") add_noko_elem(i, "annexid", node.attr("annexid")) # a = node.attr("annexid") and i.annexid a add_noko_elem(i, "amendment", node.attr("amendment-number")) # a = node.attr("amendment-number") and i.amendment a add_noko_elem(i, "corrigendum", node.attr("corrigendum-number")) # 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 |
#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
21 22 23 24 25 26 27 28 |
# File 'lib/metanorma/itu/front_id.rb', line 21 def td_id(node, xml) node.attr("td-number") or return add_noko_elem(xml, "docidentifier", node.attr("td-number"), type: "ITU-TemporaryDocument") # 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
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/metanorma/itu/validate.rb', line 123 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.strip, /^[a-z]/, t, term, "term definition does not start with capital") termdef_warn(para.text.strip, /[^.]\z/, t, term, "term definition does not end with period") end end |
#termdef_warn(text, regex, node, term, msg) ⇒ Object
135 136 137 |
# File 'lib/metanorma/itu/validate.rb', line 135 def termdef_warn(text, regex, node, term, msg) regex.match(text) && @log.add("ITU_12", node, params: [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 47 |
# File 'lib/metanorma/itu/front.rb', line 38 def title(node, xml) title_defaultlang(node, xml) title_otherlangs(node, xml) title_fallback(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
21 22 23 24 25 26 27 |
# File 'lib/metanorma/itu/front.rb', line 21 def title_defaultlang(node, xml) a = node.attr("title") || node.attr("title-#{@lang}") or return 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
37 38 39 40 41 42 43 44 |
# File 'lib/metanorma/itu/validate.rb', line 37 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("ITU_3", nil, params: [series]) end end |
#unnumbered_check(xmldoc) ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/metanorma/itu/validate.rb', line 106 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("ITU_9", c) end end |