Class: Metanorma::Jis::Converter
- Inherits:
-
Iso::Converter
- Object
- Iso::Converter
- Metanorma::Jis::Converter
- Defined in:
- lib/metanorma/jis/log.rb,
lib/metanorma/jis/front.rb,
lib/metanorma/jis/converter.rb
Constant Summary collapse
- JIS_LOG_MESSAGES =
{ # rubocop:disable Naming/VariableNumber "JIS_1": { category: "Document Attributes", error: "%s is not a recognised document type", severity: 2 }, "JIS_2": { category: "Document Attributes", error: "%s is not a recognised script", severity: 2 }, }.freeze
- LANGS =
%w(ja en).freeze
- XML_ROOT_TAG =
"jis-standard".freeze
- XML_NAMESPACE =
"https://www.metanorma.org/ns/jis".freeze
Instance Method Summary collapse
- #base_pubid ⇒ Object
- #committee_contributors(node, xml, default, opt) ⇒ Object
- #copyright_parse(node) ⇒ Object
- #default_publisher ⇒ Object
- #doc_converter(node) ⇒ Object
- #document_scheme(node) ⇒ Object
- #example_attrs(node) ⇒ Object
- #extract_org_attrs_address(node, opts, suffix) ⇒ Object
- #extract_org_attrs_complex(node, opts, source, suffix) ⇒ Object
- #get_typeabbr(node, amd: false) ⇒ Object
- #html_converter(node) ⇒ Object
- #init_i18n(node) ⇒ Object
- #init_metadata(node) ⇒ Object
- #iso_id_default(params) ⇒ Object
- #iso_id_out(xml, params, _with_prf) ⇒ Object
- #iso_id_params_add(node) ⇒ Object
- #iso_id_params_core(node) ⇒ Object
-
#log_messages ⇒ Object
rubocop:enable Naming/VariableNumber.
- #metadata_id_docidentifier(node, xml) ⇒ Object
- #metadata_id_primary_type(node) ⇒ Object
- #metadata_publisher(node, xml) ⇒ Object
- #multiling_docattr(node, attr, suffix, langs) ⇒ Object
- #multiling_noko_value(value, tag, xml) ⇒ Object
- #ol_attrs(node) ⇒ Object
- #org_abbrev ⇒ Object
- #org_attrs_complex_parse(node, opts, source) ⇒ Object
- #org_attrs_parse(node, opts) ⇒ Object
- #org_author(node, xml) ⇒ Object
- #org_organization(node, xml, org) ⇒ Object
- #organization(xml, org, node = nil, default_org = nil) ⇒ Object
- #pdf_converter(node) ⇒ Object
- #personal_author(node, xml) ⇒ Object
- #presentation_xml_converter(node) ⇒ Object
- #pub_hash ⇒ Object
- #section_attributes(node) ⇒ Object
- #title(node, xml) ⇒ Object
Instance Method Details
#base_pubid ⇒ Object
165 166 167 |
# File 'lib/metanorma/jis/front.rb', line 165 def base_pubid Pubid::Jis::Identifier end |
#committee_contributors(node, xml, default, opt) ⇒ Object
14 |
# File 'lib/metanorma/jis/front.rb', line 14 def committee_contributors(node, xml, default, opt); end |
#copyright_parse(node) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/metanorma/jis/front.rb', line 125 def copyright_parse(node) opt = { source: ["copyright-holder", "publisher", "pub"], role: "publisher", default: pub_hash } ret = org_attrs_parse(node, opt) ret.empty? and ret = [{ name: "-" }] ret end |
#default_publisher ⇒ Object
10 11 12 |
# File 'lib/metanorma/jis/front.rb', line 10 def default_publisher "JIS" end |
#doc_converter(node) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/metanorma/jis/converter.rb', line 57 def doc_converter(node) if node.nil? IsoDoc::Jis::WordConvert.new({}) else IsoDoc::Jis::WordConvert.new(doc_extract_attributes(node)) end end |
#document_scheme(node) ⇒ Object
45 46 47 |
# File 'lib/metanorma/jis/converter.rb', line 45 def document_scheme(node) node.attr("document-scheme") end |
#example_attrs(node) ⇒ Object
40 41 42 43 |
# File 'lib/metanorma/jis/converter.rb', line 40 def example_attrs(node) attr_code(id_unnum_attrs(node).merge(keep_attrs(node)) .merge("keep-separate": node.attr("keep-separate"))) end |
#extract_org_attrs_address(node, opts, suffix) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/metanorma/jis/front.rb', line 91 def extract_org_attrs_address(node, opts, suffix) %w(address phone fax email uri).each_with_object({}) do |a, m| opts[:source]&.each do |s| p = multiling_docattr(node, "#{s}-#{a}", suffix, LANGS) and m[a.to_sym] = p end end end |
#extract_org_attrs_complex(node, opts, source, suffix) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/metanorma/jis/front.rb', line 83 def extract_org_attrs_complex(node, opts, source, suffix) compact_blank({ name: multiling_docattr(node, source, suffix, LANGS), role: opts[:role], desc: opts[:desc], abbr: multiling_docattr(node, "#{source}-abbr", suffix, LANGS), logo: multiling_docattr(node, "#{source}_logo", suffix, LANGS) }) .merge(extract_org_attrs_address(node, opts, suffix)) end |
#get_typeabbr(node, amd: false) ⇒ Object
156 157 158 159 160 161 162 163 |
# File 'lib/metanorma/jis/front.rb', line 156 def get_typeabbr(node, amd: false) amd || node.attr("amendment-number") and return :amd case doctype(node) when "technical-report" then :tr when "technical-specification" then :ts when "amendment" then :amd end end |
#html_converter(node) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/metanorma/jis/converter.rb', line 49 def html_converter(node) if node.nil? IsoDoc::Jis::HtmlConvert.new({}) else IsoDoc::Jis::HtmlConvert.new(html_extract_attributes(node)) end end |
#init_i18n(node) ⇒ Object
13 14 15 16 17 |
# File 'lib/metanorma/jis/converter.rb', line 13 def init_i18n(node) node.attr("language") or node.set_attr("language", "ja") node.attr("language") == "jp" and node.set_attr("language", "ja") super end |
#init_metadata(node) ⇒ Object
19 20 21 22 |
# File 'lib/metanorma/jis/converter.rb', line 19 def (node) super @default_doctype = "japanese-industrial-standard" end |
#iso_id_default(params) ⇒ Object
194 195 196 197 198 |
# File 'lib/metanorma/jis/front.rb', line 194 def iso_id_default(params) base_pubid.create(**params) rescue StandardError => e clean_abort("Document identifier: #{e}", xml) end |
#iso_id_out(xml, params, _with_prf) ⇒ Object
188 189 190 191 192 |
# File 'lib/metanorma/jis/front.rb', line 188 def iso_id_out(xml, params, _with_prf) id = iso_id_default(params).to_s(with_publisher: false) add_noko_elem(xml, "docidentifier", id.strip, type: "JIS", primary: "true") end |
#iso_id_params_add(node) ⇒ Object
182 183 184 185 186 |
# File 'lib/metanorma/jis/front.rb', line 182 def iso_id_params_add(node) ret = { number: node.attr("amendment-number"), year: iso_id_year(node) } compact_blank(ret) end |
#iso_id_params_core(node) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/metanorma/jis/front.rb', line 169 def iso_id_params_core(node) pub = iso_id_pub(node) ret = { number: node.attr("docnumber") || "0", part: node.attr("partnumber"), series: node.attr("docseries"), language: node.attr("language") == "en" ? "E" : nil, type: get_typeabbr(node), publisher: pub[0], copublisher: pub[1..-1] }.compact ret[:copublisher].empty? and ret.delete(:copublisher) compact_blank(ret) end |
#log_messages ⇒ Object
rubocop:enable Naming/VariableNumber
15 16 17 |
# File 'lib/metanorma/jis/log.rb', line 15 def super.merge(JIS_LOG_MESSAGES) end |
#metadata_id_docidentifier(node, xml) ⇒ Object
145 146 147 148 149 150 |
# File 'lib/metanorma/jis/front.rb', line 145 def (node, xml) add_noko_elem(xml, "docidentifier", node.attr("docidentifier").sub(/^JIS /, ""), primary: "true", boilerplate: true, type: (node)) end |
#metadata_id_primary_type(node) ⇒ Object
152 153 154 |
# File 'lib/metanorma/jis/front.rb', line 152 def (node) "JIS" end |
#metadata_publisher(node, xml) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/metanorma/jis/front.rb', line 16 def (node, xml) [{ source: ["publisher", "pub"], role: "publisher", default: pub_hash }, { role: "authorizer", source: ["investigative-organization"], desc: "Investigative organization" }, { role: "authorizer", source: ["investigative-committee"], desc: "Investigative committee" }].each do |o| org_contributor(node, xml, o) end end |
#multiling_docattr(node, attr, suffix, langs) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/metanorma/jis/front.rb', line 73 def multiling_docattr(node, attr, suffix, langs) node.nil? and return nil ret = node.attr(attr + suffix) and return ret ret = langs.each_with_object({}).each do |l, m| x = node.attr("#{attr}-#{l}#{suffix}") and m[l] = x end ret.empty? and return nil compact_blank(ret) end |
#multiling_noko_value(value, tag, xml) ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/metanorma/jis/front.rb', line 100 def multiling_noko_value(value, tag, xml) if value.is_a?(Hash) value.each do |k, v| add_noko_elem(xml, tag, v, language: k) end elsif value.is_a?(Array) value.each { |a| add_noko_elem(xml, tag, a) } else add_noko_elem(xml, tag, value) end end |
#ol_attrs(node) ⇒ Object
24 25 26 27 28 |
# File 'lib/metanorma/jis/converter.rb', line 24 def ol_attrs(node) ret = super ret.delete(:type) ret end |
#org_abbrev ⇒ Object
6 7 8 |
# File 'lib/metanorma/jis/front.rb', line 6 def org_abbrev super.merge("Japanese Industrial Standards" => "JIS") end |
#org_attrs_complex_parse(node, opts, source) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/metanorma/jis/front.rb', line 61 def org_attrs_complex_parse(node, opts, source) i = 1 suffix = "" ret = [] while multiling_docattr(node, source, suffix, LANGS) ret << extract_org_attrs_complex(node, opts, source, suffix) i += 1 suffix = "_#{i}" end ret end |
#org_attrs_parse(node, opts) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/metanorma/jis/front.rb', line 52 def org_attrs_parse(node, opts) source = opts[:source]&.detect { |s| node.attr(s) } source ||= opts[:source]&.detect do |s| LANGS.detect { |l| node.attr("#{s}-#{l}") } end org_attrs_simple_parse(node, opts, source) || org_attrs_complex_parse(node, opts, source) end |
#org_author(node, xml) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/metanorma/jis/front.rb', line 28 def (node, xml) if node.attr("corporate-author") org_contributor(node, xml, { source: ["corporate-author"], role: "author" }) else org_contributor(node, xml, { source: ["publisher", "pub"], role: "author", default: pub_hash }) end end |
#org_organization(node, xml, org) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/metanorma/jis/front.rb', line 45 def org_organization(node, xml, org) organization(xml, { name: org[:name], abbr: org[:abbr] }.compact, node, !multiling_docattr(node, "publisher", "", LANGS)) org_address(org, xml) org_logo(xml, org[:logo]) end |
#organization(xml, org, node = nil, default_org = nil) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/metanorma/jis/front.rb', line 111 def organization(xml, org, node = nil, default_org = nil) org.is_a?(Hash) && org[:name] or org = { name: org } abbrevs = org_abbrev name_str = org[:name].is_a?(Hash) ? org[:name]["en"] : org[:name] n = abbrevs.invert[org[:name]] and org = { name: n, abbr: org[:name] } multiling_noko_value(org[:name], "name", xml) default_org && a = multiling_docattr(node, "subdivision", "", LANGS) and multiling_noko_value(a, "subdivision", xml) abbr = org[:abbr] abbr ||= org_abbrev[name_str] default_org && b = node&.attr("subdivision-abbr") and abbr = b add_noko_elem(xml, "abbreviation", abbr) end |
#pdf_converter(node) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/metanorma/jis/converter.rb', line 65 def pdf_converter(node) return if node.attr("no-pdf") if node.nil? IsoDoc::Jis::PdfConvert.new({}) else IsoDoc::Jis::PdfConvert.new(pdf_extract_attributes(node)) end end |
#personal_author(node, xml) ⇒ Object
200 201 202 203 |
# File 'lib/metanorma/jis/front.rb', line 200 def (node, xml) ::Metanorma::Standoc::Converter.instance_method(:personal_author).bind(self) .call(node, xml) end |
#presentation_xml_converter(node) ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/metanorma/jis/converter.rb', line 75 def presentation_xml_converter(node) if node.nil? IsoDoc::Jis::PresentationXMLConvert.new({}) else IsoDoc::Jis::PresentationXMLConvert .new(doc_extract_attributes(node) .merge(output_formats: ::Metanorma::Jis::Processor.new .output_formats)) end end |
#pub_hash ⇒ Object
41 42 43 |
# File 'lib/metanorma/jis/front.rb', line 41 def pub_hash { "ja" => "日本工業規格", "en" => "Japanese Industrial Standards" } end |
#section_attributes(node) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/metanorma/jis/converter.rb', line 30 def section_attributes(node) ret = super if node.attr("style") == "appendix" && node.level == 1 && node.option?("commentary") ret[:commentary] = true node.set_attr("obligation", "informative") end ret end |
#title(node, xml) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/metanorma/jis/front.rb', line 133 def title(node, xml) %w(en ja).each do |lang| title_full(node, xml, lang) %w(intro main part).each do |w| title_component(node, xml, lang, { name: w, abbr: w }) end @amd and title_component(node, xml, lang, { name: "amendment", abbr: "amd" }) title_nums(node, xml, lang) end end |