Class: IsoDoc::IEEE::PresentationXMLConvert
- Inherits:
-
PresentationXMLConvert
- Object
- PresentationXMLConvert
- IsoDoc::IEEE::PresentationXMLConvert
- Includes:
- Init
- Defined in:
- lib/isodoc/ieee/presentation_terms.rb,
lib/isodoc/ieee/presentation_xml_convert.rb
Instance Method Summary collapse
- #admitted_to_related(docxml) ⇒ Object
- #anchor_linkend1(node) ⇒ Object
- #block_delim ⇒ Object
- #collapse_multidef(elem) ⇒ Object
- #collapse_term(docxml) ⇒ Object
- #collapse_term1(term) ⇒ Object
- #collapse_term_related(rels) ⇒ Object
- #collapse_term_template(opt) ⇒ Object
- #collapse_unwrap_definition(defn) ⇒ Object
- #designation_field(desgn, name) ⇒ Object
- #display_order(docxml) ⇒ Object
- #eref_localities1(target, type, from, upto, node, lang = "en") ⇒ Object
- #eref_localities_conflated(refs, target, node) ⇒ Object
-
#initialize(options) ⇒ PresentationXMLConvert
constructor
A new instance of PresentationXMLConvert.
- #merge_second_preferred(term) ⇒ Object
- #multidef(elem) ⇒ Object
- #number_multidef(elem) ⇒ Object
- #prefix_clause(target, loc) ⇒ Object
- #related(docxml) ⇒ Object
- #related_term(term) ⇒ Object
- #sort_related(coll) ⇒ Object
- #sort_related_key(related) ⇒ Object
- #sort_terms_key(term) ⇒ Object
- #subclause?(target, type, from) ⇒ Boolean
- #term(docxml) ⇒ Object
- #term_related_collapse(coll) ⇒ Object
- #term_related_reorder(coll) ⇒ Object
- #terms(docxml) ⇒ Object
- #termsource1(elem) ⇒ Object
- #unwrap_definition(docxml) ⇒ Object
Methods included from Init
#fileloc, #i18n_init, #metadata_init, #xref_init
Constructor Details
#initialize(options) ⇒ PresentationXMLConvert
Returns a new instance of PresentationXMLConvert.
8 9 10 11 |
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 8 def initialize() @hierarchical_assets = [:hierarchical_assets] super end |
Instance Method Details
#admitted_to_related(docxml) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 98 def (docxml) docxml.xpath(ns("//term/admitted")).each do |a| a["type"] = "equivalent" a.name = "related" a.children = "<preferred>#{a.children.to_xml}</preferred>" end end |
#anchor_linkend1(node) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 56 def anchor_linkend1(node) linkend = @xrefs.anchor(node["target"], :xref) @xrefs.anchor(node["target"], :type) == "clause" && @xrefs.anchor(node["target"], :level) > 1 && !start_of_sentence(node) and linkend = linkend.sub(/^Clause /, "") container = @xrefs.anchor(node["target"], :container, false) prefix_container?(container, node) and linkend = prefix_container(container, linkend, node["target"]) capitalise_xref(node, linkend, anchor_value(node["target"])) end |
#block_delim ⇒ Object
68 69 70 |
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 68 def block_delim "—" end |
#collapse_multidef(elem) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 17 def collapse_multidef(elem) ins = elem.at(ns("./definition")).previous_element coll = elem.xpath(ns("./definition")) coll.each(&:remove) ins.next = "<definition>#{coll.map do |c| c.children.to_xml end }</definition>" end |
#collapse_term(docxml) ⇒ Object
106 107 108 109 110 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 106 def collapse_term(docxml) docxml.xpath(ns("//term")).each do |t| collapse_term1(t) end end |
#collapse_term1(term) ⇒ Object
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 112 def collapse_term1(term) ret = collapse_term_template( pref: term.at(ns("./preferred")).remove, def: term.at(ns("./definition")), rels: term.xpath(ns("./related")).map(&:remove), source: term.at(ns("./termsource")), ) (ins = term.elements.first and ins.previous = ret) or term << ret end |
#collapse_term_related(rels) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 123 def (rels) ret = rels.map do |r| "<em>#{@i18n.[r['type']]}:</em> "\ "#{r.at(ns('./preferred')).children.to_xml}" end.join(". ") ret += "." unless ret.empty? ret end |
#collapse_term_template(opt) ⇒ Object
132 133 134 135 136 137 138 139 140 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 132 def collapse_term_template(opt) defn = collapse_unwrap_definition(opt[:def]) source = opt[:source] ? "(#{opt[:source].remove.children.to_xml})" : nil <<~TERM <p>#{opt[:pref].children.to_xml}: #{defn} #{(opt[:rels])} #{source}</p> TERM end |
#collapse_unwrap_definition(defn) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 142 def collapse_unwrap_definition(defn) return nil if defn.nil? s = defn.remove.xpath(ns("./termsource")) p = defn.at(ns("./p")) !s.empty? && p and p << s.map(&:remove).map(&:children).map(&:to_xml).join if defn.elements.size == 1 && defn.elements.first.name == "p" defn.elements.first.children else defn.elements end end |
#designation_field(desgn, name) ⇒ Object
160 161 162 163 164 165 166 167 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 160 def designation_field(desgn, name) if desgn.name == "preferred" f = desgn.xpath(ns("./../domain | ./../subject")).map(&:remove) .map { |u| u.children.to_xml }.join(", ") name << ", <#{f}>" unless f.empty? end super end |
#display_order(docxml) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 72 def display_order(docxml) i = 0 i = display_order_xpath(docxml, "//preface/*", i) i = display_order_at(docxml, "//clause[@type = 'overview']", i) i = display_order_at(docxml, @xrefs.klass.norm_ref_xpath, i) i = display_order_at(docxml, "//sections/terms | "\ "//sections/clause[descendant::terms]", i) i = display_order_at(docxml, "//sections/definitions", i) i = display_order_xpath(docxml, @xrefs.klass.middle_clause(docxml), i) i = display_order_xpath(docxml, "//annex", i) i = display_order_xpath(docxml, @xrefs.klass.bibliography_xpath, i) display_order_xpath(docxml, "//indexsect", i) end |
#eref_localities1(target, type, from, upto, node, lang = "en") ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 39 def eref_localities1(target, type, from, upto, node, lang = "en") return nil if type == "anchor" type = type.downcase lang == "zh" and return l10n(eref_localities1_zh(target, type, from, upto, node)) ret = "" node["droploc"] != "true" && !subclause?(target, type, from) and ret = eref_locality_populate(type, node) ret += " #{from}" if from ret += "–#{upto}" if upto ret += ")" if type == "list" l10n(ret) end |
#eref_localities_conflated(refs, target, node) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 13 def eref_localities_conflated(refs, target, node) droploc = node["droploc"] node["droploc"] = true ret = resolve_eref_connectives(eref_locality_stacks(refs, target, node)) node["droploc"] = droploc eref_localities1(target, prefix_clause(target, refs.first.at(ns("./locality"))), l10n(ret[1..-1].join), nil, node, @lang) end |
#merge_second_preferred(term) ⇒ Object
169 170 171 172 173 174 175 176 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 169 def merge_second_preferred(term) super term.xpath(ns("./preferred[expression/name]")).each_with_index do |p, i| unless i.zero? p.remove # whatever was eligible to display has already been merged end end end |
#multidef(elem) ⇒ Object
4 5 6 7 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 4 def multidef(elem) number_multidef(elem) collapse_multidef(elem) end |
#number_multidef(elem) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 9 def number_multidef(elem) c = IsoDoc::XrefGen::Counter.new("@") elem.xpath(ns("./definition")).each do |d| c.increment(d) d.elements.first.previous = "<strong>(#{c.print})</strong> " end end |
#prefix_clause(target, loc) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 24 def prefix_clause(target, loc) loc["type"] == "clause" or return loc["type"] if subclause?(target, loc["type"], loc&.at(ns("./referenceFrom"))&.text) "" else "clause" end end |
#related(docxml) ⇒ Object
38 39 40 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 38 def (docxml) docxml.xpath(ns("//term[related]")).each { |f| (f) } end |
#related_term(term) ⇒ Object
42 43 44 45 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 42 def (term) coll = (term.xpath(ns("./related"))) (coll) end |
#sort_related(coll) ⇒ Object
75 76 77 78 79 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 75 def (coll) coll.sort do |a, b| (a) <=> (b) end end |
#sort_related_key(related) ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 81 def () type = case ["type"] when "contrast" then 1 when "equivalent" then 2 when "see" then 3 when "seealso" then 4 else "5-#{['type']}" end "#{type} :: #{sort_terms_key()}" end |
#sort_terms_key(term) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 59 def sort_terms_key(term) d = term.at(ns("./preferred/expression/name | "\ "./preferred/letter-designation/name | "\ "./preferred/graphical-symbol/figure/name | "\ "./preferred/graphical-symbol/figure/@id")) d&.text&.downcase end |
#subclause?(target, type, from) ⇒ Boolean
34 35 36 37 |
# File 'lib/isodoc/ieee/presentation_xml_convert.rb', line 34 def subclause?(target, type, from) (from&.match?(/\./) && type == "clause") || target&.gsub(/<[^>]+>/, "")&.match(/^IEV$|^IEC 60050-/) end |
#term(docxml) ⇒ Object
178 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 178 def term(docxml); end |
#term_related_collapse(coll) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 47 def (coll) prev = 0 coll[1..-1].each_with_index do |r, i| if coll[prev]["type"] == r["type"] coll[prev].at(ns("./preferred")) << "; #{r.at(ns('./preferred')) .children.to_xml}" r.remove else prev = i end end end |
#term_related_reorder(coll) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 67 def (coll) ins = coll.first.previous_element ret = (coll) coll.each(&:remove) ret.reverse.each { |t| ins.next = t } ins.parent.xpath(ns("./related")) end |
#terms(docxml) ⇒ Object
92 93 94 95 96 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 92 def terms(docxml) docxml super collapse_term docxml end |
#termsource1(elem) ⇒ Object
154 155 156 157 158 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 154 def termsource1(elem) while elem&.next_element&.name == "termsource" elem << "; #{elem.next_element.remove.children.to_xml}" end end |
#unwrap_definition(docxml) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/isodoc/ieee/presentation_terms.rb', line 26 def unwrap_definition(docxml) docxml.xpath(ns("//definition/verbal-definition")).each do |v| next unless v.elements.all? { |e| %w(termsource p).include?(e.name) } s = v.xpath(ns("./termsource")) p = v.xpath(ns("./p")) v.children = "<p>#{p.map(&:children).map(&:to_xml).join("\n")}</p>#{s.to_xml}" end super end |