Class: Metanorma::Iec::Converter
- Inherits:
-
ISO::Converter
- Object
- ISO::Converter
- Metanorma::Iec::Converter
- Defined in:
- lib/metanorma/iec/front.rb,
lib/metanorma/iec/converter.rb
Constant Summary collapse
- STAGE_CODES =
{ "PNW" => "1000", "ANW" => "2000", "CAN" => "2098", "ACD" => "2099", "CD" => "3020", "BWG" => "3092", "A2CD" => "3099", "2CD" => "3520", "3CD" => "3520", "4CD" => "3520", "5CD" => "3520", "6CD" => "3520", "7CD" => "3520", "8CD" => "3520", "9CD" => "3520", "CDM" => "3591", "A3CD" => "3592", "A4CD" => "3592", "A5CD" => "3592", "A6CD" => "3592", "A7CD" => "3592", "A8CD" => "3592", "A9CD" => "3592", "ACDV" => "3599", "CCDV" => "4020", "CDVM" => "4091", "NCDV" => "4092", "NADIS" => "4093", "ADIS" => "4099", "ADTR" => "4099", "ADTS" => "4099", "RDISH" => "5000", "RFDIS" => "5000", "CDISH" => "5020", "CDPAS" => "5020", "CDTR" => "5020", "CDTS" => "5020", "CFDIS" => "5020", "DTRM" => "5092", "DTSM" => "5092", "NDTR" => "5092", "NDTS" => "5092", "NFDIS" => "5092", "APUB" => "5099", "BPUB" => "6000", "PPUB" => "6060", "RR" => "9092", "AMW" => "9220", "WPUB" => "9599", "DELPUB" => "9960", "PWI" => "0000", "NWIP" => "1000", "WD" => "2000", "CDV" => "4000", "FDIS" => "5000" }.freeze
- DOC_STAGE =
{ "00": "PWI", "10": "NWIP", "20": "WD", "30": "CD", "40": "CDV", "50": "FDIS", "60": "PPUB", "90": "RR", "92": "AMW", "95": "WPUB", "99": "DELPUB", }.freeze
- STAGE_ABBRS =
{ "00" => { "00" => "PWI" }, "10" => { "00" => "PNW" }, "20" => { "00" => "ANW", "98" => "CAN", "99" => "ACD" }, "30" => { "00" => "CD", "20" => "CD", "92" => "BWG", "97" => "MERGED", "98" => "DREJ", "99" => "A2CD" }, "35" => { "00" => "CD", "20" => "CD", "91" => "CDM", "92" => "ACD", "99" => "ACDV" }, "40" => { "00" => "CCDV", "20" => "CCDV", "91" => "CDVM", "92" => "NCDV", "93" => "NADIS", "95" => "ADISSB", "99" => "ADIS" }, "50" => { "00" => "RFDIS", "20" => "CFDIS", "92" => "NFDIS", "95" => "APUBSB", "99" => "APUB" }, "60" => { "00" => "BPUB", "60" => "PPUB" }, "90" => { "00" => "RR", "92" => "RR" }, "92" => { "00" => "AMW", "20" => "AMW" }, "95" => { "00" => "WPUB", "99" => "WPUB" }, "99" => { "00" => "DELPUB", "60" => "DELPUB" }, }.freeze
- STAGE_NAMES =
{ "00": "Preliminary work item", "10": "New work item proposal", "20": "Working draft", "30": "Committee draft", "35": "Committee draft", "40": "Committed draft for vote", "50": "Final draft international standard", "60": "International standard", "90": "Review", "92": "Review", "95": "Withdrawal", "99": "Deleted", }.freeze
- XML_ROOT_TAG =
"iec-standard".freeze
- XML_NAMESPACE =
"https://www.metanorma.org/ns/iec".freeze
Instance Method Summary collapse
- #boilerplate_file(x_orig) ⇒ Object
- #doc_converter(node) ⇒ Object
- #doctype_validate(xmldoc) ⇒ Object
- #get_stage(node) ⇒ Object
- #get_substage(node) ⇒ Object
- #html_converter(node) ⇒ Object
- #id_edition_suffix(docnum, node) ⇒ Object
- #id_stage_abbr(stage, _substage, node) ⇒ Object
- #iev_variant_titles(xmldoc) ⇒ Object
- #image_name_validate(xmldoc) ⇒ Object
- #init(node) ⇒ Object
- #iso_id(node, xml) ⇒ Object
- #metadata_approval_committee(node, xml) ⇒ Object
- #metadata_author(node, xml) ⇒ Object
- #metadata_copyright(node, xml) ⇒ Object
- #metadata_ext(node, xml) ⇒ Object
- #metadata_publisher(node, xml) ⇒ Object
- #metadata_status(node, xml) ⇒ Object
- #metadata_subdoctype(node, xml) ⇒ Object
- #note(note) ⇒ Object
- #note_cleanup(xmldoc) ⇒ Object
- #ol_attrs(node) ⇒ Object
- #pdf_converter(node) ⇒ Object
- #presentation_xml_converter(node) ⇒ Object
- #sections_names_cleanup(xml) ⇒ Object
- #stage_abbr(stage, _substage) ⇒ Object
- #stage_name(stage, _substage, _doctype, _iteration) ⇒ Object
- #status_abbrev1(stage, substage, iter, doctype, _draft) ⇒ Object
- #term_defs_boilerplate(div, source, term, preface, isodoc) ⇒ Object
- #toc_cleanup(xmldoc) ⇒ Object
- #toc_iev_cleanup(xmldoc) ⇒ Object
- #validate(doc) ⇒ Object
Instance Method Details
#boilerplate_file(x_orig) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/metanorma/iec/converter.rb', line 22 def boilerplate_file(x_orig) lang = case x_orig&.at("//bibdata/language")&.text when "fr" then "fr" else "en" end File.join(@libdir, "iec_intro_#{lang}.xml") end |
#doc_converter(node) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/metanorma/iec/converter.rb', line 59 def doc_converter(node) if node.nil? IsoDoc::Iec::WordConvert.new({}) else IsoDoc::Iec::WordConvert.new(doc_extract_attributes(node)) end end |
#doctype_validate(xmldoc) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/metanorma/iec/converter.rb', line 31 def doctype_validate(xmldoc) doctype = xmldoc&.at("//bibdata/ext/doctype")&.text %w(international-standard technical-specification technical-report publicly-available-specification international-workshop-agreement guide interpretation-sheet).include? doctype or @log.add("Document Attributes", nil, "#{doctype} is not a recognised document type") if function = xmldoc&.at("//bibdata/ext/function")&.text %w(emc quality-assurance safety environment).include? function or @log.add("Document Attributes", nil, "#{function} is not a recognised document function") end end |
#get_stage(node) ⇒ Object
164 165 166 167 168 169 |
# File 'lib/metanorma/iec/front.rb', line 164 def get_stage(node) stage = node.attr("status") || node.attr("docstage") || "60" m = /([0-9])CD$/.match(stage) and node.set_attr("iteration", m[1]) STAGE_CODES[stage] and stage = STAGE_CODES[stage][0..1] stage end |
#get_substage(node) ⇒ Object
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/metanorma/iec/front.rb', line 171 def get_substage(node) st = node.attr("status") || node.attr("docstage") stage = get_stage(node) node.attr("docsubstage") || (if stage == "60" "60" else STAGE_CODES[st] ? STAGE_CODES[st][2..3] : "00" end) end |
#html_converter(node) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/metanorma/iec/converter.rb', line 51 def html_converter(node) if node.nil? IsoDoc::Iec::HtmlConvert.new({}) else IsoDoc::Iec::HtmlConvert.new(html_extract_attributes(node)) end end |
#id_edition_suffix(docnum, node) ⇒ Object
54 55 56 57 58 |
# File 'lib/metanorma/iec/front.rb', line 54 def id_edition_suffix(docnum, node) ed = node.attr("edition") || 1 docnum += " ED #{ed}" docnum end |
#id_stage_abbr(stage, _substage, node) ⇒ Object
182 183 184 185 186 187 188 |
# File 'lib/metanorma/iec/front.rb', line 182 def id_stage_abbr(stage, _substage, node) return "" if stage == "60" abbr = DOC_STAGE[stage.to_sym] || "" abbr = node.attr("iteration") + abbr if node.attr("iteration") abbr end |
#iev_variant_titles(xmldoc) ⇒ Object
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/metanorma/iec/converter.rb', line 124 def iev_variant_titles(xmldoc) id = xmldoc&.at("//bibdata/docidentifier[@type = 'ISO']")&.text m = /60050-(\d+)/.match(id) or return xmldoc.xpath("//sections/clause/terms/title").each_with_index do |t, i| num = "%02d" % [i + 1] t.next = "<variant-title type='toc'>"\ "#{@i18n.section_iev} #{m[1]}-#{num} – "\ "#{t.children.to_xml}</variant-title>" end end |
#image_name_validate(xmldoc) ⇒ Object
113 |
# File 'lib/metanorma/iec/converter.rb', line 113 def image_name_validate(xmldoc); end |
#init(node) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/metanorma/iec/converter.rb', line 14 def init(node) super if @is_iev = node.attr("docnumber") == "60050" @vocab = true node.set_attr("docsubtype", "vocabulary") end end |
#iso_id(node, xml) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/metanorma/iec/front.rb', line 44 def iso_id(node, xml) return unless node.attr("docnumber") part, subpart = node&.attr("partnumber")&.split(/-/) dn = add_id_parts(node.attr("docnumber"), part, subpart) dn = id_stage_prefix(dn, node) dn = id_edition_suffix(dn, node) xml.docidentifier dn, **attr_code(type: "ISO") end |
#metadata_approval_committee(node, xml) ⇒ Object
217 |
# File 'lib/metanorma/iec/front.rb', line 217 def (node, xml); end |
#metadata_author(node, xml) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/metanorma/iec/front.rb', line 4 def (node, xml) publishers = node.attr("publisher") || "IEC" csv_split(publishers)&.each do |p| xml.contributor do |c| c.role **{ type: "author" } c.organization do |a| organization(a, p, false, node, !node.attr("publisher")) end end end end |
#metadata_copyright(node, xml) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/metanorma/iec/front.rb', line 28 def (node, xml) publishers = node.attr("copyright-holder") || node.attr("publisher") || "IEC" csv_split(publishers)&.each do |p| xml.copyright do |c| c.from (node.attr("copyright-year") || Date.today.year) c.owner do |owner| owner.organization do |o| organization(o, p, true, node, !node.attr("copyright-holder") || node.attr("publisher")) end end end end end |
#metadata_ext(node, xml) ⇒ Object
207 208 209 210 211 212 213 214 215 |
# File 'lib/metanorma/iec/front.rb', line 207 def (node, xml) super a = node.attr("accessibility-color-inside") and xml.accessibility_color_inside a a = node.attr("price-code") and xml.price_code a a = node.attr("cen-processing") and xml.cen_processing a a = node.attr("secretary") and xml.secretary a a = node.attr("interest-to-committees") and xml.interest_to_committees a end |
#metadata_publisher(node, xml) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/metanorma/iec/front.rb', line 16 def (node, xml) publishers = node.attr("publisher") || "IEC" csv_split(publishers)&.each do |p| xml.contributor do |c| c.role **{ type: "publisher" } c.organization do |a| organization(a, p, true, node, !node.attr("publisher")) end end end end |
#metadata_status(node, xml) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/metanorma/iec/front.rb', line 190 def (node, xml) stage = get_stage(node) substage = get_substage(node) xml.status do |s| s.stage stage, **attr_code(abbreviation: stage_abbr(stage, substage)) subst = status_abbrev1(stage, substage, node.attr("iteration"), doctype(node), node.attr("draft")) s.substage substage, **attr_code(abbreviation: subst) node.attr("iteration") && (s.iteration node.attr("iteration")) end end |
#metadata_subdoctype(node, xml) ⇒ Object
202 203 204 205 |
# File 'lib/metanorma/iec/front.rb', line 202 def (node, xml) super a = node.attr("function") and xml.function a end |
#note(note) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/metanorma/iec/converter.rb', line 95 def note(note) if note.title == "Note from TC/SC Officers" noko do |xml| xml.tc_sc_officers_note do |c| wrap_in_para(note, c) end end.join("\n") else super end end |
#note_cleanup(xmldoc) ⇒ Object
107 108 109 110 111 |
# File 'lib/metanorma/iec/converter.rb', line 107 def note_cleanup(xmldoc) super n = xmldoc.at("//tc-sc-officers-note") and xmldoc.at("//bibdata/ext").add_child(n.remove) end |
#ol_attrs(node) ⇒ Object
135 136 137 138 |
# File 'lib/metanorma/iec/converter.rb', line 135 def ol_attrs(node) attr_code(keep_attrs(node) .merge(id: ::Metanorma::Utils::anchor_or_uuid(node))) end |
#pdf_converter(node) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/metanorma/iec/converter.rb', line 67 def pdf_converter(node) return if node.attr("no-pdf") if node.nil? IsoDoc::Iec::PdfConvert.new({}) else IsoDoc::Iec::PdfConvert.new(pdf_extract_attributes(node)) end end |
#presentation_xml_converter(node) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/metanorma/iec/converter.rb', line 77 def presentation_xml_converter(node) if node.nil? IsoDoc::Iec::PresentationXMLConvert.new({}) else IsoDoc::Iec::PresentationXMLConvert.new(doc_extract_attributes(node)) end end |
#sections_names_cleanup(xml) ⇒ Object
89 90 91 92 93 |
# File 'lib/metanorma/iec/converter.rb', line 89 def sections_names_cleanup(xml) super @is_iev and replace_title(xml, "//introduction", @i18n&.introduction_iev) end |
#stage_abbr(stage, _substage) ⇒ Object
154 155 156 157 158 |
# File 'lib/metanorma/iec/front.rb', line 154 def stage_abbr(stage, _substage) return "PPUB" if stage == "60" DOC_STAGE[stage.to_sym] || "??" end |
#stage_name(stage, _substage, _doctype, _iteration) ⇒ Object
160 161 162 |
# File 'lib/metanorma/iec/front.rb', line 160 def stage_name(stage, _substage, _doctype, _iteration) STAGE_NAMES[stage.to_sym] end |
#status_abbrev1(stage, substage, iter, doctype, _draft) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/metanorma/iec/front.rb', line 128 def status_abbrev1(stage, substage, iter, doctype, _draft) return "" unless stage abbr = STAGE_ABBRS.dig(stage, substage) || "??" if stage == "35" && substage == "92" iter = (iter.to_i + 1) % "02" end case doctype when "technical-report" abbr = "ADTR" if stage == "40" && substage == "99" abbr = "CDTR" if stage == "50" && substage == "20" abbr = "DTRM" if stage == "50" && substage == "92" when "technical-specification" abbr = "ADTS" if stage == "40" && substage == "99" abbr = "CDTS" if stage == "50" && substage == "20" abbr = "DTSM" if stage == "50" && substage == "92" when "interpretation-sheet" abbr = "RDISH" if stage == "50" && substage == "00" abbr = "CDISH" if stage == "50" && substage == "20" when "publicly-available-specification" abbr = "CDPAS" if stage == "50" && substage == "20" end abbr = abbr.sub(/CD$/, "#{iter}CD") if iter abbr end |
#term_defs_boilerplate(div, source, term, preface, isodoc) ⇒ Object
85 86 87 |
# File 'lib/metanorma/iec/converter.rb', line 85 def term_defs_boilerplate(div, source, term, preface, isodoc) return super unless @is_iev end |
#toc_cleanup(xmldoc) ⇒ Object
115 116 117 118 |
# File 'lib/metanorma/iec/converter.rb', line 115 def toc_cleanup(xmldoc) toc_iev_cleanup(xmldoc) if @is_iev super end |
#toc_iev_cleanup(xmldoc) ⇒ Object
120 121 122 |
# File 'lib/metanorma/iec/converter.rb', line 120 def toc_iev_cleanup(xmldoc) iev_variant_titles(xmldoc) end |
#validate(doc) ⇒ Object
45 46 47 48 49 |
# File 'lib/metanorma/iec/converter.rb', line 45 def validate(doc) content_validate(doc) schema_validate(formattedstr_strip(doc.dup), File.join(File.dirname(__FILE__), "iec.rng")) end |