Class: Metanorma::Ieee::Converter
- Inherits:
-
Standoc::Converter
- Object
- Standoc::Converter
- Metanorma::Ieee::Converter
- Defined in:
- lib/metanorma/ieee/log.rb,
lib/metanorma/ieee/front.rb,
lib/metanorma/ieee/converter.rb
Constant Summary collapse
- IEEE_LOG_MESSAGES =
{ # rubocop:disable Naming/VariableNumber "IEEE_2": { category: "Style", error: "%s is a 4-digit number in a table column with numbers broken up in threes", severity: 2 }, "IEEE_3": { category: "Style", error: "Expected title to start as: %s", severity: 2 }, "IEEE_4": { category: "Style", error: "Title contains uncapitalised word other than preposition", severity: 2 }, "IEEE_5": { category: "Document Attributes", error: "%s is not a recognised document type", severity: 2 }, "IEEE_6": { category: "Document Attributes", error: "%s is not a recognised document subtype", severity: 2 }, "IEEE_7": { category: "Document Attributes", error: "%s is not a recognised stage", severity: 2 }, "IEEE_8": { category: "Style", error: "Cross-reference contains range, should be separate cross-references", severity: 2 }, "IEEE_9": { category: "Style", error: "Undated reference %s should not contain specific elements", severity: 2 }, "IEEE_10": { category: "Style", error: "Normative reference %s is not dated.", severity: 2 }, "IEEE_11": { category: "Style", error: "Use ordered lists for lists more than two levels deep.", severity: 2 }, "IEEE_12": { category: "Style", error: "Ordered lists should not be more than five levels deep.", severity: 2 }, "IEEE_13": { category: "Style", error: "Image name %s is expected to be %s", severity: 2 }, # "IEEE_15": { category: "Style", error: "More than one image in the table cell", severity: 2 }, "IEEE_16": { category: "Style", error: "Editorial instruction is missing from change", severity: 2 }, "IEEE_17": { category: "Style", error: "'Add' change description should start with _Insert_", severity: 2 }, "IEEE_18": { category: "Style", error: "'Delete' change description should start with _Delete_", severity: 2 }, "IEEE_19": { category: "Style", error: "'Modify' change description should start with _Change_ or _Replace_", severity: 2 }, "IEEE_20": { category: "Style", error: "'Modify' change description for change involving figure or equation should start with _Replace_", severity: 2 }, "IEEE_21": { category: "Style", error: "'Modify' change description for change not involving figure or equation should start with _Change_", severity: 2 }, "IEEE_22": { category: "Style", error: "Overview clause missing", severity: 2 }, "IEEE_23": { category: "Style", error: "Scope subclause missing", severity: 2 }, "IEEE_24": { category: "Style", error: "Word Usage subclause missing", severity: 2 }, "IEEE_25": { category: "Style", error: "Normative references missing", severity: 2 }, "IEEE_26": { category: "Style", error: "Definitions missing", severity: 2 }, "IEEE_27": { category: "Style", error: "(section sequencing) %s", severity: 2 }, "IEEE_28": { category: "Style", error: "Document must include (references) Normative References", severity: 2 }, # "IEEE_30": { category: "Style", error: "subclause is only child", severity: 2 }, "IEEE_31": { category: "Style", error: "Bibliography must be either the first or the last document annex", severity: 2 }, }.freeze
- PREFACE_CLAUSE_NAMES =
%w(abstract foreword introduction acknowledgements participants metanorma-extension misc-container).freeze
Instance Method Summary collapse
- #base_pubid ⇒ Object
- #clause_attrs_preprocess(attrs, node) ⇒ Object
- #committee_contrib_org_prep(node, type, agency, _opts) ⇒ Object
- #committee_contributors(node, xml, agency, opt) ⇒ Object
- #compact_blank(hash) ⇒ Object
- #contributors_committees_nest1(committees) ⇒ Object
- #datetypes ⇒ Object
- #default_publisher ⇒ Object
- #doc_converter(node) ⇒ Object
- #doc_extract_attributes(node) ⇒ Object
- #html_converter(node) ⇒ Object
- #html_extract_attributes(node) ⇒ Object
- #ieee_draft_numbers(node) ⇒ Object
- #ieee_id_out(xml, params) ⇒ Object
- #ieee_id_params(node) ⇒ Object
- #ieee_id_params_amd(node, core) ⇒ Object
- #ieee_id_params_core(node) ⇒ Object
- #ieee_id_pub(node) ⇒ Object
- #ieee_id_year(node, initial: false) ⇒ Object
- #ieee_xml_converter(node) ⇒ Object
- #init(node) ⇒ Object
-
#log_messages ⇒ Object
rubocop:enable Naming/VariableNumber.
- #metadata_committee_prep(node) ⇒ Object
- #metadata_committee_types(_node) ⇒ Object
- #metadata_ext(node, xml) ⇒ Object
- #metadata_id_nonprimary(node, xml) ⇒ Object
- #metadata_id_primary(node, xml) ⇒ Object
- #metadata_id_primary_type(_node) ⇒ Object
- #metadata_other_id(node, xml) ⇒ Object
- #metadata_status(node, xml) ⇒ Object
- #metadata_subdoctype(node, xml) ⇒ Object
- #org_abbrev ⇒ Object
- #org_attrs_add_committees(node, ret, opts, opts_orig) ⇒ Object
- #outputs(node, ret) ⇒ Object
- #pdf_converter(node) ⇒ Object
- #presentation_xml_converter(node) ⇒ Object
- #program(node, xml) ⇒ Object
- #pubid_select(_params) ⇒ Object
- #relaton_relations ⇒ Object
- #sectiontype_streamline(ret) ⇒ Object
- #structured_id(node, xml) ⇒ Object
- #termsource_attrs(node, matched) ⇒ Object
- #title_other(node, xml) ⇒ Object
Instance Method Details
#base_pubid ⇒ Object
141 142 143 |
# File 'lib/metanorma/ieee/front.rb', line 141 def base_pubid Pubid::Ieee::Identifier end |
#clause_attrs_preprocess(attrs, node) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/metanorma/ieee/converter.rb', line 31 def clause_attrs_preprocess(attrs, node) case node.title.downcase when "purpose" then attrs[:type] = "purpose" when "overview" then attrs[:type] = "overview" when "scope" then attrs[:type] = "scope" when "word usage" then attrs[:type] = "word-usage" when "participants" then attrs[:type] = "participants" end super end |
#committee_contrib_org_prep(node, type, agency, _opts) ⇒ Object
50 51 52 |
# File 'lib/metanorma/ieee/front.rb', line 50 def committee_contrib_org_prep(node, type, agency, _opts) super.merge(role: "authorizer") end |
#committee_contributors(node, xml, agency, opt) ⇒ Object
23 24 25 26 |
# File 'lib/metanorma/ieee/front.rb', line 23 def committee_contributors(node, xml, agency, opt) (node) or return super end |
#compact_blank(hash) ⇒ Object
86 87 88 |
# File 'lib/metanorma/ieee/front.rb', line 86 def compact_blank(hash) hash.compact.reject { |_, v| v.is_a?(String) && v.empty? } end |
#contributors_committees_nest1(committees) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/metanorma/ieee/front.rb', line 39 def contributors_committees_nest1(committees) committees.empty? and return committees committees = committees.map(&:reverse).reverse.flatten committees.each_with_index do |m, i| i.zero? and next m[:subdiv] = committees[i - 1] end committees[-1].nil? and return [] [committees[-1]] end |
#datetypes ⇒ Object
158 159 160 |
# File 'lib/metanorma/ieee/front.rb', line 158 def datetypes super + %w{feedback-ended ieee-sasb-approved} end |
#default_publisher ⇒ Object
145 146 147 |
# File 'lib/metanorma/ieee/front.rb', line 145 def default_publisher "IEEE" end |
#doc_converter(node) ⇒ Object
88 89 90 |
# File 'lib/metanorma/ieee/converter.rb', line 88 def doc_converter(node) IsoDoc::Ieee::WordConvert.new(doc_extract_attributes(node)) end |
#doc_extract_attributes(node) ⇒ Object
66 67 68 69 70 |
# File 'lib/metanorma/ieee/converter.rb', line 66 def doc_extract_attributes(node) super.merge(hierarchicalassets: node.attr("hierarchical-object-numbering"), ulstyle: "l11", olstyle: "l16") end |
#html_converter(node) ⇒ Object
78 79 80 |
# File 'lib/metanorma/ieee/converter.rb', line 78 def html_converter(node) IsoDoc::Ieee::HtmlConvert.new(html_extract_attributes(node)) end |
#html_extract_attributes(node) ⇒ Object
60 61 62 63 64 |
# File 'lib/metanorma/ieee/converter.rb', line 60 def html_extract_attributes(node) super.merge(hierarchicalassets: node.attr("hierarchical-object-numbering"), ieeedtd: node.attr("ieee-dtd")) end |
#ieee_draft_numbers(node) ⇒ Object
103 104 105 106 107 |
# File 'lib/metanorma/ieee/front.rb', line 103 def ieee_draft_numbers(node) draft = node.attr("draft") or return nil d = draft.split(".") { version: d[0], revision: d[1] }.compact end |
#ieee_id_out(xml, params) ⇒ Object
131 132 133 134 135 |
# File 'lib/metanorma/ieee/front.rb', line 131 def ieee_id_out(xml, params) add_noko_elem(xml, "docidentifier", pubid_select(params).create(**params).to_s, type: "IEEE", primary: "true") end |
#ieee_id_params(node) ⇒ Object
80 81 82 83 84 |
# File 'lib/metanorma/ieee/front.rb', line 80 def ieee_id_params(node) core = ieee_id_params_core(node) amd = ieee_id_params_amd(node, core) || {} core.merge(amd) end |
#ieee_id_params_amd(node, core) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/metanorma/ieee/front.rb', line 109 def ieee_id_params_amd(node, core) if a = node.attr("corrigendum-number") { corrigendum: { version: a, year: ieee_id_year(node, initial: false) } } elsif node.attr("amendment-number") { amendment: pubid_select(core).create(**core) } end end |
#ieee_id_params_core(node) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/metanorma/ieee/front.rb', line 90 def ieee_id_params_core(node) pub = ieee_id_pub(node) ret = { number: node.attr("docnumber"), part: node.attr("partnumber"), year: ieee_id_year(node, initial: true), draft: ieee_draft_numbers(node), redline: @doctype == "redline", publisher: pub[0], copublisher: pub[1..-1] } ret[:copublisher].empty? and ret.delete(:copublisher) compact_blank(ret) end |
#ieee_id_pub(node) ⇒ Object
118 119 120 121 |
# File 'lib/metanorma/ieee/front.rb', line 118 def ieee_id_pub(node) (node.attr("publisher") || default_publisher).split(/[;,]/) .map(&:strip).map { |x| org_abbrev[x] || x } end |
#ieee_id_year(node, initial: false) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/metanorma/ieee/front.rb', line 123 def ieee_id_year(node, initial: false) unless initial y = node.attr("copyright-year") || node.attr("updated-date") end y ||= node.attr("published-date") || node.attr("copyright-year") y&.sub(/-.*$/, "") || Date.today.year end |
#ieee_xml_converter(node) ⇒ Object
92 93 94 95 96 |
# File 'lib/metanorma/ieee/converter.rb', line 92 def ieee_xml_converter(node) return nil if node.attr("no-pdf") IsoDoc::Iso::IeeeXMLConvert.new(html_extract_attributes(node)) end |
#init(node) ⇒ Object
12 13 14 15 16 |
# File 'lib/metanorma/ieee/converter.rb', line 12 def init(node) super @document_scheme ||= "ieee-sa-2021" @hierarchical_assets = node.attr("hierarchical-object-numbering") end |
#log_messages ⇒ Object
rubocop:enable Naming/VariableNumber
95 96 97 |
# File 'lib/metanorma/ieee/log.rb', line 95 def super.merge(IEEE_LOG_MESSAGES) end |
#metadata_committee_prep(node) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/metanorma/ieee/front.rb', line 7 def (node) node.attr("doctype") == "whitepaper" && node.attr("docsubtype") == "industry-connection-report" and node.set_attr("working-group", "IEEE SA Industry Connections activity") node.attr("committee") || node.attr("society") || node.attr("working-group") or return node.attr("balloting-group") && !node.attr("balloting-group-type") and node.set_attr("balloting-group-type", "individual") true end |
#metadata_committee_types(_node) ⇒ Object
19 20 21 |
# File 'lib/metanorma/ieee/front.rb', line 19 def (_node) %w(society balloting-group working-group committee) end |
#metadata_ext(node, xml) ⇒ Object
176 177 178 179 180 |
# File 'lib/metanorma/ieee/front.rb', line 176 def (node, xml) super add_noko_elem(xml, "trial_use", node.attr("trial-use")) program(node, xml) end |
#metadata_id_nonprimary(node, xml) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/metanorma/ieee/front.rb', line 63 def (node, xml) add_noko_elem(xml, "docidentifier", node.attr("stdid-pdf"), type: "IEEE", scope: "PDF") add_noko_elem(xml, "docidentifier", node.attr("stdid-print"), type: "IEEE", scope: "print") end |
#metadata_id_primary(node, xml) ⇒ Object
70 71 72 73 74 |
# File 'lib/metanorma/ieee/front.rb', line 70 def (node, xml) params = ieee_id_params(node) params[:number] or return ieee_id_out(xml, params) end |
#metadata_id_primary_type(_node) ⇒ Object
76 77 78 |
# File 'lib/metanorma/ieee/front.rb', line 76 def (_node) "IEEE" end |
#metadata_other_id(node, xml) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/metanorma/ieee/front.rb', line 54 def (node, xml) (node, xml) add_noko_elem(xml, "docidentifier", node.attr("isbn-pdf"), type: "ISBN", scope: "PDF") add_noko_elem(xml, "docidentifier", node.attr("isbn-print"), type: "ISBN", scope: "print") add_noko_elem(xml, "docnumber", node.attr("docnumber")) end |
#metadata_status(node, xml) ⇒ Object
149 150 151 152 153 154 155 156 |
# File 'lib/metanorma/ieee/front.rb', line 149 def (node, xml) status = node.attr("status") || node.attr("docstage") || (node.attr("version") || node.attr("draft") ? "draft" : "approved") xml.status do |s| add_noko_elem(s, "stage", status, abbreviation: node.attr("docstage-abbrev")) end end |
#metadata_subdoctype(node, xml) ⇒ Object
162 163 164 |
# File 'lib/metanorma/ieee/front.rb', line 162 def (node, xml) add_noko_elem(xml, "subdoctype", node.attr("docsubtype") || "document") end |
#org_abbrev ⇒ Object
166 167 168 169 170 |
# File 'lib/metanorma/ieee/front.rb', line 166 def org_abbrev { "Institute of Electrical and Electronic Engineers" => "IEEE", "International Organization for Standardization" => "ISO", "International Electrotechnical Commission" => "IEC" } end |
#org_attrs_add_committees(node, ret, opts, opts_orig) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/metanorma/ieee/front.rb', line 28 def org_attrs_add_committees(node, ret, opts, opts_orig) opts_orig[:groups]&.each_with_index do |g, i| i.zero? and next 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 |
#outputs(node, ret) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/metanorma/ieee/converter.rb', line 48 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
82 83 84 85 86 |
# File 'lib/metanorma/ieee/converter.rb', line 82 def pdf_converter(node) return nil if node.attr("no-pdf") IsoDoc::Ieee::PdfConvert.new(pdf_extract_attributes(node)) end |
#presentation_xml_converter(node) ⇒ Object
72 73 74 75 76 |
# File 'lib/metanorma/ieee/converter.rb', line 72 def presentation_xml_converter(node) IsoDoc::Ieee::PresentationXMLConvert .new(html_extract_attributes(node) .merge(output_formats: ::Metanorma::Ieee::Processor.new.output_formats)) end |
#program(node, xml) ⇒ Object
182 183 184 |
# File 'lib/metanorma/ieee/front.rb', line 182 def program(node, xml) add_noko_elem(xml, "program", node.attr("program")) end |
#pubid_select(_params) ⇒ Object
137 138 139 |
# File 'lib/metanorma/ieee/front.rb', line 137 def pubid_select(_params) base_pubid end |
#relaton_relations ⇒ Object
172 173 174 |
# File 'lib/metanorma/ieee/front.rb', line 172 def relaton_relations super + %w(merges updates) end |
#sectiontype_streamline(ret) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/metanorma/ieee/converter.rb', line 22 def sectiontype_streamline(ret) case ret when "definitions", "definitions, acronyms and abbreviations" "terms and definitions" when "acronyms and abbreviations" then "symbols and abbreviated terms" else super end end |
#structured_id(node, xml) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/metanorma/ieee/front.rb', line 186 def structured_id(node, xml) node.attr("docnumber") or return xml.structuredidentifier do |i| add_noko_elem(i, "docnumber", node.attr("docnumber")) add_noko_elem(i, "agency", "IEEE") i.class_ doctype(node) add_noko_elem(i, "edition", node.attr("edition")) add_noko_elem(i, "version", (node)) add_noko_elem(i, "amendment", node.attr("amendment-number")) add_noko_elem(i, "corrigendum", node.attr("corrigendum-number")) add_noko_elem(i, "year", node.attr("copyright-year")) end end |
#termsource_attrs(node, matched) ⇒ Object
42 43 44 45 46 |
# File 'lib/metanorma/ieee/converter.rb', line 42 def termsource_attrs(node, matched) ret = super node.option? "adapted" and ret[:status] = "adapted" ret end |
#title_other(node, xml) ⇒ Object
200 201 202 203 204 205 |
# File 'lib/metanorma/ieee/front.rb', line 200 def title_other(node, xml) t = node.attr("title-full") and add_title_xml(xml, t, @lang, "title-full") t = node.attr("title-abbrev") and add_title_xml(xml, t, @lang, "title-abbrev") end |