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



55
56
57
# File 'lib/relaton/render/parse.rb', line 55

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)



82
83
84
85
86
# File 'lib/relaton/render/parse.rb', line 82

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

#authoritative_identifier(doc) ⇒ Object



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

def authoritative_identifier(doc)
  ret = super
  bcp = Array(doc.series).detect do |s|
    %w(BCP STD).include?(Array(s.title).first&.content)
  end
  bcp and ret.unshift("BCP\u00A0#{bcp.number}")
  ret.reject { |x| /(rfc-anchor|Internet-Draft)/.match?(x) }
    .map { |x| x.gsub(/<\/?esc>/, "").tr(" ", "\u00A0") }
end

#creatornames1(doc) ⇒ Object

return authors and editors together



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

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

  add1 = pick_contributor(doc, "author") || []
  add2 = pick_contributor(doc, "editor") || []
  cr = add1 + add2
  cr.empty? or return cr
  super
end

#creatornames_roles_allowedObject

allow publisher for standards



25
26
27
28
# File 'lib/relaton/render/parse.rb', line 25

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

#date(doc, host) ⇒ Object

not just year-only



100
101
102
103
104
# File 'lib/relaton/render/parse.rb', line 100

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

#extract(doc) ⇒ Object



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

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

#extract_orgabbrev(org) ⇒ Object



73
74
75
# File 'lib/relaton/render/parse.rb', line 73

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

#extract_personname(person) ⇒ Object



88
89
90
91
92
93
94
95
96
97
# File 'lib/relaton/render/parse.rb', line 88

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



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/relaton/render/parse.rb', line 59

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
# 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
end

#included_xml2hash(doc) ⇒ Object



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

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



47
48
49
50
51
52
53
# File 'lib/relaton/render/parse.rb', line 47

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



43
44
45
# File 'lib/relaton/render/parse.rb', line 43

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

#parse_single_bibitem(doc) ⇒ Object



167
168
169
170
171
172
# File 'lib/relaton/render/parse.rb', line 167

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



131
132
133
134
135
136
# File 'lib/relaton/render/parse.rb', line 131

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



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

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



127
128
129
# File 'lib/relaton/render/parse.rb', line 127

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)



149
150
151
152
153
# File 'lib/relaton/render/parse.rb', line 149

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



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

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