require "isodoc" require_relative "metadata" require_relative "xref" require_relative "i18n" module IsoDoc module IEEE module Init def metadata_init(lang, script, locale, i18n) @meta = Metadata.new(lang, script, locale, i18n) end def xref_init(lang, script, _klass, i18n, options) html = HtmlConvert.new(language: lang, script: script) options = options.merge(hierarchicalassets: @hierarchical_assets) @xrefs = Xref.new(lang, script, html, i18n, options) end def i18n_init(lang, script, locale, i18nyaml = nil) @i18n = I18n.new(lang, script, locale: locale, i18nyaml: i18nyaml || @i18nyaml) end def fileloc(loc) File.join(File.dirname(__FILE__), loc) end def std_docid_semantic(id) id.nil? and return nil ret = Nokogiri::XML.fragment(id) ret.traverse do |x| x.text? or next x.replace(std_docid_semantic1(x.text)) end to_xml(ret) end def std_docid_semantic1(id) ids = id.split(/\p{Zs}/) agency?(ids[0].sub(/\/.*$/, "")) or return id std_docid_semantic_full(id) end # AGENCY+ TYPE NUMBER YEAR def std_docid_semantic_full(ident) m = ident.match(%r{(?[^0-9]+\p{Zs}) (?[0-9]+) (?:[:](?(?:19|20)\d\d))?}x) m or return ident ret = std_docid_sdo(m[:text]) + "#{m[:num]}" m[:yr] and ret += ":#{m[:yr]}" ret.gsub(%r{(\p{Zs}+)<}, "\\1<") end def std_docid_sdo(text) found = false text.split(%r{([\p{Zs}|/]+)}).reverse.map do |x| if /[A-Za-z]/.match?(x) k = if found || agency?(x) then "std_publisher" else "std_documentType" end found = true "#{x}" else x end end.reverse.join.gsub(%r{(\p{Zs}+)<}, "\\1<") end end end end