Module: Relaton::Ietf::BibXMLParser

Extended by:
BibXMLParser
Included in:
BibXMLParser
Defined in:
lib/relaton/ietf/bibxml_parser.rb

Overview

rubocop:disable Metrics/ModuleLength

Defined Under Namespace

Classes: FromRfc, FromRfcxml

Instance Method Summary collapse

Instance Method Details

#build_org(abbr, name) ⇒ Object



66
67
68
69
70
# File 'lib/relaton/ietf/bibxml_parser.rb', line 66

def build_org(abbr, name)
  args = { name: [Bib::TypedLocalizedString.new(content: name, language: "en")] }
  args[:abbreviation] = Bib::LocalizedString.new(content: abbr, language: "en") if abbr && !abbr.empty?
  Bib::Organization.new(**args)
end

#full_name_org(name) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/relaton/ietf/bibxml_parser.rb', line 25

def full_name_org(name) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
  case name
  when "ISO"
    build_org(name, "International Organization for Standardization")
  when "IAB"
    build_org(name, "Internet Architecture Board")
  when "IESG"
    build_org(name, "Internet Engineering Steering Group")
  when "IANA"
    build_org(name, "Internet Assigned Numbers Authority")
  when "International Organization for Standardization"
    build_org("ISO", name)
  when "Federal Networking Council", "Internet Architecture Board", "Internet Activities Board",
    "Defense Advanced Research Projects Agency", "National Science Foundation",
    "National Research Council", "National Bureau of Standards",
    "Internet Engineering Steering Group"
    abbr = name.split.map { |w| w[0] if w[0] == w[0].upcase }.join
    build_org(abbr, name)
  when "IETF Secretariat"
    build_org("IETF", name)
  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", "IAB and IESG",
    "RARE WG-MSG Task Force 88", "KOI8-U Working Group", "The Internet Society",
    "IAB Advisory Committee", "ISOC Board of Trustees", "Mitra", "RFC Editor, et al."
    build_org(nil, name)
  when "Internet Assigned Numbers Authority (IANA)"
    build_org("IANA", "Internet Assigned Numbers Authority (IANA)")
  when "ESnet Site Coordinating Comittee (ESCC)"
    build_org("ESCC", "ESnet Site Coordinating Comittee (ESCC)")
  when "Energy Sciences Network (ESnet)"
    build_org("ESnet", "Energy Sciences Network (ESnet)")
  when "International Telegraph and Telephone Consultative Committee of the International Telecommunication Union"
    build_org("CCITT", name)
  end
end

#parse(xml) ⇒ Object



6
7
8
9
# File 'lib/relaton/ietf/bibxml_parser.rb', line 6

def parse(xml)
  reference = Rfcxml::V3::Reference.from_xml(xml)
  FromRfcxml.new(reference).transform
end

#parse_rfc(xml) ⇒ Object



11
12
13
14
# File 'lib/relaton/ietf/bibxml_parser.rb', line 11

def parse_rfc(xml)
  rfc = Rfcxml::V3::Rfc.from_xml(xml)
  FromRfc.new(rfc).transform
end

#parse_surname_initials(fname, sname, inits) ⇒ Array<String, nil>

Parse name, surname, and initials from full name

Parameters:

  • fname (String)

    full name

  • sname (String, nil)

    surname

  • inits (String, nil)

Returns:

  • (Array<String, nil>)

    surname, initials, forename



81
82
83
84
85
86
87
# File 'lib/relaton/ietf/bibxml_parser.rb', line 81

def parse_surname_initials(fname, sname, inits) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
  regex = /(?:(?<name>\w{3,})\s)?(?<inits>(?:[A-Z]{1,2}(?:\.[\s-]?|\s))+)?/
  match = fname&.match(regex)
  surname = sname || fname&.sub(regex, "")&.strip
  initials = inits || (match && match[:inits]&.strip)
  [surname, initials, (match && match[:name])]
end

#pubid_type(id) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/relaton/ietf/bibxml_parser.rb', line 16

def pubid_type(id)
  pref = id.match(/^(\S+)/)[1]
  case pref
  when "BCP", "FYI", "STD", "RFC" then "RFC"
  when "I-D" then "Internet-Draft"
  else "IETF"
  end
end