Class: Relaton::Render::Ietf::Parse

Inherits:
Parse
  • Object
show all
Defined in:
lib/relaton/render/parse.rb

Constant Summary collapse

XML2RFC_STREAMS =

the enumeration admits per v3.rng, keyed by downcased relaton stream title

{
  "iab" => "IAB", "ietf" => "IETF", "irtf" => "IRTF",
  "independent" => "independent",
  "independent submission" => "independent"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Parse

Returns a new instance of Parse.



5
6
7
8
# File 'lib/relaton/render/parse.rb', line 5

def initialize(options)
  super
  @fieldsklass = Relaton::Render::Ietf::Fields
end

Instance Method Details

#abstract(doc) ⇒ Object



62
63
64
# File 'lib/relaton/render/parse.rb', line 62

def abstract(doc)
  Array(doc.abstract).map { |a| content(a) }.join
end

#ascii_or_nil(str) ⇒ Object

The ascii attributes are computed here, nil when the transliteration is redundant, so the nametemplates emit them through a bare presence check, and downstream consumers (incl. the presentation XML transformer) inherit already-clean output: xml2rfc strips self-equal ascii attributes with a warning (#269)



89
90
91
92
93
# File 'lib/relaton/render/parse.rb', line 89

def ascii_or_nil(str)
  str.nil? and return nil
  a = str.transliterate
  a == str ? nil : a
end

#authoritative_identifier(doc) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/relaton/render/parse.rb', line 128

def authoritative_identifier(doc)
  ret = super
  bcp = Array(doc.series).detect do |s|
    %w(BCP STD).include?(Array(s.title).first&.content)
  end
  # label the sub-series by its own title: the unconditional
  # "BCP" prefix rendered every STD-series RFC as BCP
  # (STD 63 -> "BCP 63", #282)
  bcp and ret.unshift(
    "#{Array(bcp.title).first&.content}\u00A0#{bcp.number}",
  )
  # Internet-Draft identifiers stay: rejecting them (as the
  # rfc-anchor internals rightly are) left draft references
  # with NO seriesInfo, so xml2rfc never rendered "Work in
  # Progress, Internet-Draft, draft-name" (#283). Only the
  # unversioned duplicate of the primary id is dropped.
  primary = ret.grep(/Internet-Draft/).max_by(&:length)
  ret.reject do |x|
    /rfc-anchor/.match?(x) ||
      (/Internet-Draft/.match?(x) && x != primary) ||
      # the I-D. anchor form duplicates the real draft name
      # with an unprefixed, unversioned value — drop it when
      # a proper Internet-Draft identifier is present
      (primary && /I-D\./.match?(x))
  end
    .map { |x| x.gsub(/<\/?esc>/, "").tr(" ", "\u00A0") }
end

#creatornames1(doc) ⇒ Object

return authors and editors together, in DOCUMENT order: concatenating all authors then all editors re-ordered mixed lists — RFC 5234 (data order Crocker (ed.), Overell) rendered as "Overell, P. and D. Crocker", and organisational authors were hoisted over persons (#284)



118
119
120
121
122
123
124
125
126
# File 'lib/relaton/render/parse.rb', line 118

def creatornames1(doc)
  return [] if doc.nil?

  cr = Array(doc.contributor).select do |c|
    Array(c.role).any? { |r| %w(author editor).include?(r.type) }
  end
  cr.empty? or return cr
  super
end

#creatornames_roles_allowedObject

allow publisher for standards



32
33
34
35
# File 'lib/relaton/render/parse.rb', line 32

def creatornames_roles_allowed
  %w(author performer adapter translator editor publisher distributor
     authorizer)
end

#date(doc, host) ⇒ Object

not just year-only



107
108
109
110
111
# File 'lib/relaton/render/parse.rb', line 107

def date(doc, host)
  ret = date1(Array(doc.date))
  host and ret ||= date1(Array(host.date))
  datepick(ret)
end

#extract(doc) ⇒ Object



184
185
186
# File 'lib/relaton/render/parse.rb', line 184

def extract(doc)
  super.merge(included_xml2hash(doc))
end

#extract_orgabbrev(org) ⇒ Object



80
81
82
# File 'lib/relaton/render/parse.rb', line 80

def extract_orgabbrev(org)
  content(org.abbreviation)
end

#extract_personname(person) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/relaton/render/parse.rb', line 95

def extract_personname(person)
  sn = content(person.name.surname)
  cn = content(person.name.completename)
  given, middle, initials = given_and_middle_name(person)
  { surname: sn, completename: cn,
    given: given, middle: middle, initials: initials,
    surnameascii: ascii_or_nil(sn),
    completenameascii: ascii_or_nil(cn),
    initialsascii: ascii_or_nil(Array(initials).join) }.compact
end

#extractname(contributor) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/relaton/render/parse.rb', line 66

def extractname(contributor)
  org = contributor.organization
  person = contributor.person
  if org
    name = extract_orgname(org)
    return { nonpersonal: name,
             nonpersonalascii: ascii_or_nil(name),
             nonpersonalabbrev: extract_orgabbrev(org) }
  end
  return extract_personname(person) if person

  nil
end

#home_standard(doc, pubs) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/relaton/render/parse.rb', line 17

def home_standard(doc, pubs)
  pubs&.any? do |r|
    ["Internet Engineering Task Force", "IETF", "RFC Publisher"]
      .include?(r[:nonpersonal])
  end ||
    # an Internet-Draft is an IETF-stream document even though
    # its relaton record carries no publisher contributor;
    # without this, draft references fell to the refcontent
    # branch and never got the seriesInfo that makes xml2rfc
    # render "Work in Progress, Internet-Draft, ..." (#283)
    Array(doc.docidentifier)
      .any? { |i| i.type == "Internet-Draft" }
end

#included_xml2hash(doc) ⇒ Object



188
189
190
191
192
193
194
# File 'lib/relaton/render/parse.rb', line 188

def included_xml2hash(doc)
  r = Array(doc.relation).select { |x| x.type == "includes" }.map do |x|
    parse_single_bibitem(x.bibitem)
  end
  r.empty? and return {}
  { included: r }
end

#keyword1(kw) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/relaton/render/parse.rb', line 54

def keyword1(kw)
  v = Array(kw.vocab).first
  v and return content(v)
  t = Array(kw.taxon).first
  t and return content(t)
  kw.vocabid&.term
end

#keywords(doc) ⇒ Object



50
51
52
# File 'lib/relaton/render/parse.rb', line 50

def keywords(doc)
  Array(doc.keyword).map { |u| keyword1(u) }.compact
end

#parse_single_bibitem(doc) ⇒ Object



196
197
198
199
200
201
# File 'lib/relaton/render/parse.rb', line 196

def parse_single_bibitem(doc)
  extract(doc)
  # enhance_data(data, r.template_raw)
  # data_liquid = @fieldsklass.new(renderer: self)
  #  .compound_fields_format(data)
end

#series(doc) ⇒ Object



160
161
162
163
164
165
# File 'lib/relaton/render/parse.rb', line 160

def series(doc)
  a = Array(doc.series).reject { |s| s.type == "stream" }
  a.empty? and return nil
  a.detect { |s| s.type == "main" } ||
    a.detect { |s| s.type.nil? } || a.first
end

#series_xml2hash1(series, doc) ⇒ Object



37
38
39
40
41
42
# File 'lib/relaton/render/parse.rb', line 37

def series_xml2hash1(series, doc)
  ret = super
  plain_title = ret[:series_title]&.gsub(/<\/?esc>/, "")
  %w(BCP RFC I-D. Internet-Draft).include?(plain_title) and return {}
  ret
end

#simple_or_host_xml2hash(doc, host) ⇒ Object



10
11
12
13
14
15
# File 'lib/relaton/render/parse.rb', line 10

def simple_or_host_xml2hash(doc, host)
  ret = super
  ret.merge(home_standard: home_standard(doc, ret[:publisher_raw]),
            uris: uris(doc), keywords: keywords(doc),
            abstract: abstract(doc))
end

#simple_xml2hash(doc) ⇒ Object



156
157
158
# File 'lib/relaton/render/parse.rb', line 156

def simple_xml2hash(doc)
  super.merge(stream: stream(doc))
end

#stream(doc) ⇒ Object

Normalise the stream to the xml2rfc enumeration; values outside it (Legacy et al.) are omitted rather than emitted verbatim, which was fatal to xml2rfc (INDEPENDENT, #270)



178
179
180
181
182
# File 'lib/relaton/render/parse.rb', line 178

def stream(doc)
  a = Array(doc.series).detect { |s| s.type == "stream" } or return nil
  t = Array(a.title).first&.content or return nil
  XML2RFC_STREAMS[t.downcase]
end

#uris(doc) ⇒ Object



44
45
46
47
48
# File 'lib/relaton/render/parse.rb', line 44

def uris(doc)
  Array(doc.source).map do |u|
    { content: u.content.to_s.strip, type: u.type }
  end
end