Module: IsoDoc::Function::References

Included in:
Common
Defined in:
lib/isodoc/function/references.rb

Instance Method Summary collapse

Instance Method Details

#bibitem_ref_code(bib) ⇒ Object

returns [metanorma, non-metanorma, DOI/ISSN/ISBN] identifiers



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/isodoc/function/references.rb', line 71

def bibitem_ref_code(bib)
  id = bib.at(ns("./docidentifier[@type = 'metanorma']"))
  id1 = pref_ref_code(bib)
  id2 = bib.at(ns("./docidentifier[@type = 'DOI' or @type = 'ISSN' or "\
                  "@type = 'ISBN']"))
  id3 = bib.at(ns("./docidentifier[@type = 'metanorma-ordinal']"))
  return [id, id1, id2, id3] if id || id1 || id2 || id3
  return [nil, nil, nil, nil] if bib["suppress_identifier"] == "true"

  id = Nokogiri::XML::Node.new("docidentifier", bib.document)
  id << "(NO ID)"
  [nil, id, nil, nil]
end

#biblio_list(refs, div, biblio) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/isodoc/function/references.rb', line 165

def biblio_list(refs, div, biblio)
  i = 0
  refs.children.each do |b|
    if b.name == "bibitem"
      next if implicit_reference(b)

      i += 1 unless b["hidden"]
      if standard?(b) then std_bibitem_entry(div, b, i, biblio)
      else nonstd_bibitem(div, b, i, biblio)
      end
    else
      parse(b, div) unless %w(title).include? b.name
    end
  end
end

#bibliography(isoxml, out) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
# File 'lib/isodoc/function/references.rb', line 206

def bibliography(isoxml, out)
  (f = isoxml.at(ns(bibliography_xpath)) and f["hidden"] != "true") or
    return
  page_break(out)
  out.div do |div|
    div.h1 **{ class: "Section3" } do |h1|
      f.at(ns("./title"))&.children&.each { |c2| parse(c2, h1) }
    end
    biblio_list(f, div, true)
  end
end

#bibliography_parse(node, out) ⇒ Object



218
219
220
221
222
223
224
225
# File 'lib/isodoc/function/references.rb', line 218

def bibliography_parse(node, out)
  node["hidden"] != true or return
  out.div do |div|
    clause_parse_title(node, div, node.at(ns("./title")), out,
                       { class: "Section3" })
    biblio_list(node, div, true)
  end
end

#bibliography_xpathObject



200
201
202
203
204
# File 'lib/isodoc/function/references.rb', line 200

def bibliography_xpath
  "//bibliography/clause[.//references]"\
    "[not(.//references[@normative = 'true'])] | "\
    "//bibliography/references[@normative = 'false']"
end

#bracket_if_num(num) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/isodoc/function/references.rb', line 85

def bracket_if_num(num)
  return nil if num.nil?

  num = num.text.sub(/^\[/, "").sub(/\]$/, "")
  return "[#{num}]" if /^\d+$/.match?(num)

  num
end

#date_note_process(bib, ref) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/isodoc/function/references.rb', line 126

def date_note_process(bib, ref)
  date_note = bib.at(ns("./note[@type = 'Unpublished-Status']"))
  return if date_note.nil?

  date_note.children = "<p>#{date_note.content}</p>"
  footnote_parse(date_note, ref)
end

#docid_l10n(text) ⇒ 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
10
11
# File 'lib/isodoc/function/references.rb', line 6

def docid_l10n(text)
  return text if text.nil?

  text.gsub(/All Parts/i, @i18n.all_parts.downcase) if @i18n.all_parts
  text
end

#docid_prefix(prefix, docid) ⇒ Object



113
114
115
116
117
# File 'lib/isodoc/function/references.rb', line 113

def docid_prefix(prefix, docid)
  docid = "#{prefix} #{docid}" if prefix && !omit_docid_prefix(prefix) &&
    !/^#{prefix}\b/.match(docid)
  docid_l10n(docid)
end

#implicit_reference(bib) ⇒ Object

reference not to be rendered because it is deemed implicit in the standards environment



140
141
142
# File 'lib/isodoc/function/references.rb', line 140

def implicit_reference(bib)
  bib["hidden"] == "true"
end

#iso_bibitem_entry_attrs(bib, biblio) ⇒ Object



134
135
136
# File 'lib/isodoc/function/references.rb', line 134

def iso_bibitem_entry_attrs(bib, biblio)
  { id: bib["id"], class: biblio ? "Biblio" : "NormRef" }
end

#nonstd_bibitem(list, bib, ordinal, biblio) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/isodoc/function/references.rb', line 13

def nonstd_bibitem(list, bib, ordinal, biblio)
  list.p **attr_code(iso_bibitem_entry_attrs(bib, biblio)) do |ref|
    ids = bibitem_ref_code(bib)
    idents = render_identifier(ids)
    if biblio then ref_entry_code(ref, ordinal, idents, ids)
    else
      ref << (idents[:ordinal] || idents[:metanorma] || idents[:sdo]).to_s
      ref << ", #{idents[sdo]}" if idents[:ordinal] && idents[:sdo]
    end
    ref << "," if idents[:sdo]
    ref << " "
    reference_format(bib, ref)
  end
end

#norm_ref(isoxml, out, num) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/isodoc/function/references.rb', line 186

def norm_ref(isoxml, out, num)
  (f = isoxml.at(ns(norm_ref_xpath)) and f["hidden"] != "true") or
    return num
  out.div do |div|
    num += 1
    clause_name(num, f.at(ns("./title")), div, nil)
    if f.name == "clause"
      f.elements.each { |e| parse(e, div) unless e.name == "title" }
    else biblio_list(f, div, false)
    end
  end
  num
end

#norm_ref_xpathObject



181
182
183
184
# File 'lib/isodoc/function/references.rb', line 181

def norm_ref_xpath
  "//bibliography/references[@normative = 'true'] | "\
    "//bibliography/clause[.//references[@normative = 'true']]"
end

#omit_docid_prefix(prefix) ⇒ Object



119
120
121
122
123
124
# File 'lib/isodoc/function/references.rb', line 119

def omit_docid_prefix(prefix)
  return true if prefix.nil? || prefix.empty?

  %w(ISO IEC IEV ITU W3C BIPM csd metanorma repository metanorma-ordinal)
    .include? prefix
end

#pref_ref_code(bib) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/isodoc/function/references.rb', line 52

def pref_ref_code(bib)
  return nil if bib["suppress_identifier"] == "true"

  ret = bib.xpath(ns("./docidentifier[@primary = 'true'][@language = '#{@lang}']"))
  ret.empty? and
    ret = bib.xpath(ns("./docidentifier[@primary = 'true']"))
  ret.empty? and
    ret = bib.at(ns(<<~XPATH,
                   )) ||
      bib.at(ns(<<~XPATH,
        ./docidentifier[not(@type = 'DOI' or @type = 'metanorma' or @type = 'metanorma-ordinal' or @type = 'ISSN' or @type = 'ISBN')]
      XPATH
               ))
  ret
end

#prefix_bracketed_ref(ref, text) ⇒ Object



144
145
146
147
# File 'lib/isodoc/function/references.rb', line 144

def prefix_bracketed_ref(ref, text)
  ref << text.to_s
  insert_tab(ref, 1)
end

#ref_entry_code(ref, ordinal, ids, _id) ⇒ Object

if ids is just a number, only use that ([1] Non-Standard) else, use both ordinal, as prefix, and ids



46
47
48
49
50
# File 'lib/isodoc/function/references.rb', line 46

def ref_entry_code(ref, ordinal, ids, _id)
  prefix_bracketed_ref(ref, ids[:ordinal] || ids[:metanorma] ||
                       "[#{ordinal}]")
  ids[:sdo] and ref << (ids[:sdo]).to_s
end

#reference_format(bib, out) ⇒ Object



149
150
151
152
# File 'lib/isodoc/function/references.rb', line 149

def reference_format(bib, out)
  ftitle = bib.at(ns("./formattedref"))
  ftitle&.children&.each { |n| parse(n, out) }
end

#render_identifier(ident) ⇒ Object



106
107
108
109
110
111
# File 'lib/isodoc/function/references.rb', line 106

def render_identifier(ident)
  { metanorma: bracket_if_num(ident[0]),
    sdo: unbracket(ident[1]),
    doi: unbracket(ident[2]),
    ordinal: bracket_if_num(ident[3]) }
end

#standard?(bib) ⇒ Boolean

Returns:

  • (Boolean)


154
155
156
157
158
159
160
161
162
163
# File 'lib/isodoc/function/references.rb', line 154

def standard?(bib)
  ret = false
  drop = %w(metanorma DOI ISSN ISBN)
  bib.xpath(ns("./docidentifier")).each do |id|
    next if id["type"].nil? || drop.include?(id["type"])

    ret = true
  end
  ret
end

#std_bibitem_entry(list, bib, ordinal, biblio) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/isodoc/function/references.rb', line 28

def std_bibitem_entry(list, bib, ordinal, biblio)
  list.p **attr_code(iso_bibitem_entry_attrs(bib, biblio)) do |ref|
    idents = render_identifier(bibitem_ref_code(bib))
    if biblio then ref_entry_code(ref, ordinal, idents, nil)
    else
      ref << (idents[:ordinal] || idents[:metanorma] || idents[:sdo]).to_s
      ref << ", #{idents[:sdo]}" if (idents[:ordinal] ||
                                    idents[:metanorma]) && idents[:sdo]
    end
    date_note_process(bib, ref)
    ref << "," if idents[:sdo]
    ref << " "
    reference_format(bib, ref)
  end
end

#unbracket(ident) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/isodoc/function/references.rb', line 98

def unbracket(ident)
  if ident.respond_to?(:size)
    ident.map { |x| unbracket1(x) }.join("&#xA0;/ ")
  else
    unbracket1(ident)
  end
end

#unbracket1(ident) ⇒ Object



94
95
96
# File 'lib/isodoc/function/references.rb', line 94

def unbracket1(ident)
  ident&.text&.sub(/^\[/, "")&.sub(/\]$/, "")
end