Class: RelatonIetf::RfcEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_ietf/rfc_entry.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ RfcEntry

Initalize parser



8
9
10
# File 'lib/relaton_ietf/rfc_entry.rb', line 8

def initialize(doc)
  @doc = doc
end

Class Method Details

.parse(doc) ⇒ RelatonIetf::IetfBibliographicItem

Initialize parser & parse document



19
20
21
# File 'lib/relaton_ietf/rfc_entry.rb', line 19

def self.parse(doc)
  new(doc).parse
end

Instance Method Details

#codeString

Parse document code



111
112
113
# File 'lib/relaton_ietf/rfc_entry.rb', line 111

def code
  @doc.at("./xmlns:doc-id").text
end

#docnumString

Parse document number



102
103
104
# File 'lib/relaton_ietf/rfc_entry.rb', line 102

def docnum
  /\d+$/.match(code).to_s.sub(/^0+/, "")
end

#initials(int) ⇒ Array<RelatonBib::LocalizedString>

Ctreat initials



199
200
201
202
203
# File 'lib/relaton_ietf/rfc_entry.rb', line 199

def initials(int)
  return [] unless int

  int.split(/\.-?\s?|\s/).map { |i| RelatonBib::LocalizedString.new i, "en", "Latn" }
end

#parseRelatonIetf::IetfBibliographicItem

Parse document



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/relaton_ietf/rfc_entry.rb', line 28

def parse # rubocop:disable Metrics/MethodLength
  IetfBibliographicItem.new(
    type: "standard",
    language: ["en"],
    script: ["Latn"],
    fetched: Date.today.to_s,
    docid: parse_docid,
    docnumber: code,
    title: parse_title,
    link: parse_link,
    date: parse_date,
    contributor: parse_contributor,
    keyword: parse_keyword,
    abstract: parse_abstract,
    relation: parse_relation,
    status: parse_status,
    series: parse_series,
    editorialgroup: parse_editorialgroup,
  )
end

#parse_abstractArray<RelatonBib::FormattedString>

Parse document abstract



219
220
221
222
223
224
225
226
227
# File 'lib/relaton_ietf/rfc_entry.rb', line 219

def parse_abstract
  @doc.xpath("./xmlns:abstract").map do |c|
    content = c.xpath("./xmlns:p").map do |p|
      "<#{p.name}>#{p.text.strip}</#{p.name}>"
    end.join
    RelatonBib::FormattedString.new(content: content, language: "en",
                                    script: "Latn", format: "text/html")
  end
end

#parse_contributorArray<RelatonBib::ContributionInfo>

Parse document contributors



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/relaton_ietf/rfc_entry.rb', line 145

def parse_contributor # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
  @doc.xpath("./xmlns:author").map do |contributor| # rubocop:disable Metrics/BlockLength
    n = contributor.at("./xmlns:name").text
    case n
    when "ISO"
      entity = RelatonBib::Organization.new(abbrev: n, name: "International Organization for Standardization")
    when "International Organization for Standardization"
      entity = RelatonBib::Organization.new(abbrev: "ISO", name: n)
    when "IAB"
      entity = RelatonBib::Organization.new(abbrev: n, name: "Internet Architecture Board")
    when "IESG"
      entity = RelatonBib::Organization.new(abbrev: n, name: "Internet Engineering Steering Group")
    when "Internet Engineering Steering Group", "Federal Networking Council", "Internet Architecture Board",
      "Internet Activities Board", "Defense Advanced Research Projects Agency", "National Science Foundation",
      "National Research Council", "National Bureau of Standards"
      abbr = n.split.map { |w| w[0] if w[0] == w[0].upcase }.join
      entity = RelatonBib::Organization.new(abbrev: abbr, name: n)
    when "IETF Secretariat"
      entity = RelatonBib::Organization.new(abbrev: "IETF", name: n)
    when "Audio-Video Transport Working Group", /North American Directory Forum/, "EARN Staff",
      "Vietnamese Standardization Working Group", "ACM SIGUCCS", "ESCC X.500/X.400 Task Force",
      "Sun Microsystems", "NetBIOS Working Group in the Defense Advanced Research Projects Agency",
      "End-to-End Services Task Force", "Network Technical Advisory Group", "Bolt Beranek",
      "Newman Laboratories", "Gateway Algorithms and Data Structures Task Force",
      "Network Information Center. Stanford Research Institute", "RFC Editor",
      "Information Sciences Institute University of Southern California"
      entity = RelatonBib::Organization.new(name: n)
    when "Internet Assigned Numbers Authority (IANA)"
      entity = RelatonBib::Organization.new(abbrev: "IANA", name: "Internet Assigned Numbers Authority")
    when "ESnet Site Coordinating Comittee (ESCC)"
      entity = RelatonBib::Organization.new(abbrev: "ESCC", name: "ESnet Site Coordinating Comittee")
    when "Energy Sciences Network (ESnet)"
      entity = RelatonBib::Organization.new(abbrev: "ESnet", name: "Energy Sciences Network")
    when "International Telegraph and Telephone Consultative Committee of the International Telecommunication Union"
      entity = RelatonBib::Organization.new(abbrev: "CCITT", name: n)
    else
      # int, snm = n.split
      /^(?:(?<int>(?:\p{Lu}+(?:-\w|\(\w\))?\.{0,2}[-\s]?)+)\s)?(?<snm>[[:alnum:]\s'-.]+)$/ =~ n
      surname = RelatonBib::LocalizedString.new(snm, "en", "Latn")
      name = RelatonBib::LocalizedString.new(n, "en", "Latn")
      fname = RelatonBib::FullName.new(completename: name, initial: initials(int), surname: surname)
      entity = RelatonBib::Person.new(name: fname)
    end
    RelatonBib::ContributionInfo.new(entity: entity, role: [{ type: "author" }])
  end
end

#parse_dateArray<RelatonBib::BibliographicDate>

Parse document date



131
132
133
134
135
136
137
138
# File 'lib/relaton_ietf/rfc_entry.rb', line 131

def parse_date
  @doc.xpath("./xmlns:date").map do |date|
    month = date.at("./xmlns:month").text
    year = date.at("./xmlns:year").text
    on = "#{year}-#{Date::MONTHNAMES.index(month).to_s.rjust(2, '0')}"
    RelatonBib::BibliographicDate.new(on: on, type: "published")
  end
end

#parse_docidArray<RelatonBib::DocumentIdettifier>

Parse document identifiers



68
69
70
71
72
73
74
75
76
# File 'lib/relaton_ietf/rfc_entry.rb', line 68

def parse_docid
  ids = [
    RelatonBib::DocumentIdentifier.new(id: pub_id, type: "IETF", primary: true),
    RelatonBib::DocumentIdentifier.new(id: code, type: "IETF", scope: "anchor"),
  ]
  doi = @doc.at("./xmlns:doi").text
  ids << RelatonBib::DocumentIdentifier.new(id: doi, type: "DOI")
  ids
end

#parse_editorialgroupRelatonBib::EditorialGroup

Parse document editorial group



258
259
260
261
262
263
264
# File 'lib/relaton_ietf/rfc_entry.rb', line 258

def parse_editorialgroup
  tc = @doc.xpath("./xmlns:wg_acronym").map do |wg|
    wg = RelatonBib::WorkGroup.new(name: wg.text)
    RelatonBib::TechnicalCommittee.new(wg)
  end
  RelatonBib::EditorialGroup.new(tc)
end

#parse_keywordArray<String>

Parse document keywords



210
211
212
# File 'lib/relaton_ietf/rfc_entry.rb', line 210

def parse_keyword
  @doc.xpath("./xmlns:keywords/xmlns:kw").map &:text
end

Create link



120
121
122
123
124
# File 'lib/relaton_ietf/rfc_entry.rb', line 120

def parse_link
  num = code[-4..-1].sub(/^0+/, "")
  url = "https://www.rfc-editor.org/info/rfc#{num}"
  [RelatonBib::TypedUri.new(content: url, type: "src")]
end

#parse_relationArra<RelatonBib::DocumentRelation>

Parse document relations



234
235
236
237
238
239
240
241
# File 'lib/relaton_ietf/rfc_entry.rb', line 234

def parse_relation
  types = { "updates" => "updates", "obsoleted-by" => "obsoletedBy"}
  @doc.xpath("./xmlns:updates/xmlns:doc-id|./xmlns:obsoleted-by/xmlns:doc-id").map do |r|
    fref = RelatonBib::FormattedRef.new(content: r.text)
    bib = IetfBibliographicItem.new(formattedref: fref)
    RelatonBib::DocumentRelation.new(type: types[r.parent.name], bibitem: bib)
  end
end

#parse_seriesArray<RelatonBib::Series>

Parse series



54
55
56
57
58
59
60
61
# File 'lib/relaton_ietf/rfc_entry.rb', line 54

def parse_series
  title = RelatonBib::TypedTitleString.new(content: "RFC")
  @doc.xpath("./xmlns:is-also/xmlns:doc-id").map do |s|
    /^(?<name>\D+)(?<num>\d+)/ =~ s.text
    t = RelatonBib::TypedTitleString.new(content: name)
    RelatonBib::Series.new title: t, number: num.gsub(/^0+/, "")
  end + [RelatonBib::Series.new(title: title, number: docnum)]
end

#parse_statusRelatonBib::DocuemntStatus

Parse document status



248
249
250
251
# File 'lib/relaton_ietf/rfc_entry.rb', line 248

def parse_status
  stage = @doc.at("./xmlns:current-status").text
  RelatonBib::DocumentStatus.new(stage: stage)
end

#parse_titleArray<RelatonBib::TypedTileString>

Parse document title



83
84
85
86
# File 'lib/relaton_ietf/rfc_entry.rb', line 83

def parse_title
  content = @doc.at("./xmlns:title").text
  [RelatonBib::TypedTitleString.new(content: content, type: "main")]
end

#pub_idString

Create PubID



93
94
95
# File 'lib/relaton_ietf/rfc_entry.rb', line 93

def pub_id
  "RFC #{docnum}"
end