Module: IsoDoc::Function::References
- Included in:
- Common
- Defined in:
- lib/isodoc/function/references.rb
Constant Summary collapse
- ISO_PUBLISHER_XPATH =
"./contributor[xmlns:role/@type = 'publisher']/"\ "organization[abbreviation = 'ISO' or xmlns:abbreviation = 'IEC' or "\ "xmlns:name = 'International Organization for Standardization' or "\ "xmlns:name = 'International Electrotechnical Commission']".freeze
- BIBLIOGRAPHY_XPATH =
"//bibliography/clause[title = 'Bibliography'] | "\ "//bibliography/references[title = 'Bibliography']".freeze
Instance Method Summary collapse
- #bibitem_ref_code(b) ⇒ Object
- #biblio_list(f, div, bibliography) ⇒ Object
- #bibliography(isoxml, out) ⇒ Object
- #bibliography_parse(node, out) ⇒ Object
- #date_note_process(b, ref) ⇒ Object
-
#docid_l10n(x) ⇒ Object
This is highly specific to ISO, but it’s not a bad precedent for references anyway; keeping here instead of in IsoDoc::Iso for now.
- #docid_prefix(prefix, docid) ⇒ Object
- #format_ref(ref, prefix, isopub, date, allparts) ⇒ Object
-
#implicit_reference(b) ⇒ Object
reference not to be rendered because it is deemed implicit in the standards environment.
- #is_standard(b) ⇒ Object
- #iso_bibitem_entry_attrs(b, biblio) ⇒ Object
- #iso_title(b) ⇒ Object
-
#nonstd_bibitem(list, b, ordinal, bibliography) ⇒ Object
TODO generate formatted ref if not present.
- #norm_ref(isoxml, out, num) ⇒ Object
- #omit_docid_prefix(prefix) ⇒ Object
- #prefix_bracketed_ref(ref, text) ⇒ Object
-
#ref_entry_code(r, ordinal, t, id) ⇒ Object
if t is just a number, only use that ([1] Non-Standard) else, use both ordinal, as prefix, and t.
- #reference_format(b, r) ⇒ Object
- #reference_names(ref) ⇒ Object
- #render_identifier(id) ⇒ Object
- #std_bibitem_entry(list, b, ordinal, biblio) ⇒ Object
Instance Method Details
#bibitem_ref_code(b) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/isodoc/function/references.rb', line 50 def bibitem_ref_code(b) id = b.at(ns("./docidentifier[not(@type = 'DOI' or @type = 'metanorma' or @type = 'ISSN' or @type = 'ISBN')]")) id ||= b.at(ns("./docidentifier[not(@type = 'DOI' or @type = 'ISSN' or @type = 'ISBN')]")) id ||= b.at(ns("./docidentifier")) return id if id id = Nokogiri::XML::Node.new("docidentifier", b.document) id.text = "(NO ID)" id end |
#biblio_list(f, div, bibliography) ⇒ Object
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/isodoc/function/references.rb', line 131 def biblio_list(f, div, bibliography) f.xpath(ns("./bibitem")).each_with_index do |b, i| next if implicit_reference(b) if(is_standard(b)) std_bibitem_entry(div, b, i + 1, bibliography) else nonstd_bibitem(div, b, i + 1, bibliography) end end end |
#bibliography(isoxml, out) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/isodoc/function/references.rb', line 161 def bibliography(isoxml, out) f = isoxml.at(ns(BIBLIOGRAPHY_XPATH)) || return page_break(out) out.div do |div| div.h1 @bibliography_lbl, **{ class: "Section3" } f.elements.reject do |e| ["reference", "title", "bibitem"].include? e.name end.each { |e| parse(e, div) } biblio_list(f, div, true) end end |
#bibliography_parse(node, out) ⇒ Object
173 174 175 176 177 178 179 180 181 182 |
# File 'lib/isodoc/function/references.rb', line 173 def bibliography_parse(node, out) title = node&.at(ns("./title"))&.text || "" out.div do |div| div.h2 title, **{ class: "Section3" } node.elements.reject do |e| ["reference", "title", "bibitem"].include? e.name end.each { |e| parse(e, div) } biblio_list(node, div, true) end end |
#date_note_process(b, ref) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/isodoc/function/references.rb', line 74 def date_note_process(b, ref) date_note = b.at(ns("./note[text()][contains(.,'ISO DATE:')]")) return if date_note.nil? date_note.content = date_note.content.gsub(/ISO DATE: /, "") date_note.children.first.replace("<p>#{date_note.content}</p>") footnote_parse(date_note, ref) end |
#docid_l10n(x) ⇒ Object
This is highly specific to ISO, but it’s not a bad precedent for references anyway; keeping here instead of in IsoDoc::Iso for now
6 7 8 9 |
# File 'lib/isodoc/function/references.rb', line 6 def docid_l10n(x) return x if x.nil? x.gsub(/All Parts/i, @all_parts_lbl.downcase) end |
#docid_prefix(prefix, docid) ⇒ Object
64 65 66 67 |
# File 'lib/isodoc/function/references.rb', line 64 def docid_prefix(prefix, docid) docid = "#{prefix} #{docid}" if prefix && !omit_docid_prefix(prefix) docid_l10n(docid) end |
#format_ref(ref, prefix, isopub, date, allparts) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/isodoc/function/references.rb', line 184 def format_ref(ref, prefix, isopub, date, allparts) if isopub #if date #on = date.at(ns("./on")) #ref += on&.text == "--" ? ":--" : "" # ":#{date_range(date)}" #ref += " (all parts)" if allparts # ref = docid_prefix(prefix, ref) #end end ref = docid_prefix(prefix, ref) return "[#{ref}]" if /^\d+$/.match(ref) && !prefix && !/^\[.*\]$/.match(ref) ref end |
#implicit_reference(b) ⇒ Object
reference not to be rendered because it is deemed implicit in the standards environment
96 97 98 |
# File 'lib/isodoc/function/references.rb', line 96 def implicit_reference(b) false end |
#is_standard(b) ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/isodoc/function/references.rb', line 122 def is_standard(b) ret = false b.xpath(ns("./docidentifier")).each do |id| next if id["type"].nil? || %w(metanorma DOI ISSN ISBN).include?(id["type"]) ret = true end ret end |
#iso_bibitem_entry_attrs(b, biblio) ⇒ Object
82 83 84 |
# File 'lib/isodoc/function/references.rb', line 82 def iso_bibitem_entry_attrs(b, biblio) { id: b["id"], class: biblio ? "Biblio" : "NormRef" } end |
#iso_title(b) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/isodoc/function/references.rb', line 86 def iso_title(b) title = b.at(ns("./title[@language = '#{@lang}' and @type = 'main']")) || b.at(ns("./title[@language = '#{@lang}']")) || b.at(ns("./title[@type = 'main']")) || b.at(ns("./title")) title end |
#nonstd_bibitem(list, b, ordinal, bibliography) ⇒ Object
TODO generate formatted ref if not present
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/isodoc/function/references.rb', line 12 def nonstd_bibitem(list, b, ordinal, bibliography) list.p **attr_code(iso_bibitem_entry_attrs(b, bibliography)) do |r| id = bibitem_ref_code(b) identifier = render_identifier(id) if bibliography ref_entry_code(r, ordinal, identifier, id) else r << "#{identifier}, " end reference_format(b, r) end end |
#norm_ref(isoxml, out, num) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/isodoc/function/references.rb', line 142 def norm_ref(isoxml, out, num) q = "//bibliography/references[title = 'Normative References' or "\ "title = 'Normative references']" f = isoxml.at(ns(q)) or return num out.div do |div| num = num + 1 clause_name(num, @normref_lbl, div, nil) f.elements.reject do |e| ["reference", "title", "bibitem"].include? e.name end.each { |e| parse(e, div) } biblio_list(f, div, false) end num end |
#omit_docid_prefix(prefix) ⇒ Object
69 70 71 72 |
# File 'lib/isodoc/function/references.rb', line 69 def omit_docid_prefix(prefix) return true if prefix.nil? || prefix.empty? return ["ISO", "IEC", "metanorma"].include? prefix end |
#prefix_bracketed_ref(ref, text) ⇒ Object
100 101 102 103 |
# File 'lib/isodoc/function/references.rb', line 100 def prefix_bracketed_ref(ref, text) ref << "[#{text}]" insert_tab(ref, 1) end |
#ref_entry_code(r, ordinal, t, id) ⇒ Object
if t is just a number, only use that ([1] Non-Standard) else, use both ordinal, as prefix, and t
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/isodoc/function/references.rb', line 39 def ref_entry_code(r, ordinal, t, id) if id["type"] == "metanorma" prefix_bracketed_ref(r, t) else prefix_bracketed_ref(r, ordinal) if !t.empty? && !%w(DOI ISSN ISBN).include?(id["type"]) r << "#{t}, " end end end |
#reference_format(b, r) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/isodoc/function/references.rb', line 105 def reference_format(b, r) if ftitle = b.at(ns("./formattedref")) ftitle&.children&.each { |n| parse(n, r) } else title = iso_title(b) r.i do |i| title&.children&.each { |n| parse(n, i) } end end end |
#reference_names(ref) ⇒ Object
198 199 200 201 202 203 204 205 206 |
# File 'lib/isodoc/function/references.rb', line 198 def reference_names(ref) isopub = ref.at(ns(ISO_PUBLISHER_XPATH)) docid = bibitem_ref_code(ref) prefix = docid["type"] date = ref.at(ns("./date[@type = 'published']")) allparts = ref.at(ns("./extent[@type='part'][referenceFrom='all']")) reference = format_ref(docid_l10n(docid.text), prefix, isopub, date, allparts) @anchors[ref["id"]] = { xref: reference } end |
#render_identifier(id) ⇒ Object
60 61 62 |
# File 'lib/isodoc/function/references.rb', line 60 def render_identifier(id) docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, "")) end |
#std_bibitem_entry(list, b, ordinal, biblio) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/isodoc/function/references.rb', line 25 def std_bibitem_entry(list, b, ordinal, biblio) list.p **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref| prefix_bracketed_ref(ref, ordinal) if biblio id = bibitem_ref_code(b) identifier = render_identifier(id) ref << identifier date_note_process(b, ref) ref << ", " reference_format(b, ref) end end |