Module: RelatonIetf::BibXMLParser

Extended by:
BibXMLParser
Includes:
RelatonBib::BibXMLParser
Included in:
BibXMLParser
Defined in:
lib/relaton_ietf/bibxml_parser.rb

Instance Method Summary collapse

Instance Method Details

#bib_item(**attrs) ⇒ RelatonIetf::IetfBibliographicItem

Parameters:

  • attrs (Hash)

Returns:



11
12
13
14
15
16
17
# File 'lib/relaton_ietf/bibxml_parser.rb', line 11

def bib_item(**attrs)
  unless attrs.delete(:is_relation)
    # attrs[:fetched] = Date.today.to_s
    # attrs[:place] = ["Fremont, CA"]
  end
  RelatonIetf::IetfBibliographicItem.new(**attrs)
end

#committee(wgr) ⇒ RelatonIetf::Committee

Parameters:

  • (RelatonBib::WorkGroup)

Returns:



47
48
49
# File 'lib/relaton_ietf/bibxml_parser.rb', line 47

def committee(wgr)
  Committee.new wgr
end

#contributors(reference) ⇒ Array<Hash>

Parameters:

  • reference (Nokogiri::XML::Element)

Returns:

  • (Array<Hash>)


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

def contributors(reference)
  contribs = []
  unless reference[:anchor]&.match?(/^I-D/)
    contribs << {
      entity: new_org("Internet Engineering Task Force", "IETF"),
      role: [type: "publisher"],
    }
  end
  contribs + super
end

#forename(initials, name, lang = nil, script = nil) ⇒ Array<RelatonBib::Forename>

Create forenames with initials

Parameters:

  • initials (String)

    initials

  • lang (String) (defaults to: nil)

    language

Returns:

  • (Array<RelatonBib::Forename>)

    forenames



140
141
142
143
144
145
146
147
148
149
150
# File 'lib/relaton_ietf/bibxml_parser.rb', line 140

def forename(initials, name, lang = nil, script = nil)
  fnames = []
  if name
    fnames << RelatonBib::Forename.new(content: name, language: lang, script: script)
  end
  return fnames unless initials

  initials.split(/\.-?\s?|\s/).each_with_object(fnames) do |i, a|
    a << RelatonBib::Forename.new(initial: i, language: lang, script: script)
  end
end

#full_name(fname, sname, inits, lang, script = nil) ⇒ RelatonBib::FullName

Overrade RelatonBib::BibXMLParser#full_name method

Parameters:

  • fname (String)

    full name

  • sname (String, nil)

    surname

  • fname (String, nil)

    first name

  • lang (String, nil)

    language

  • script (String, nil) (defaults to: nil)

    script

Returns:

  • (RelatonBib::FullName)


122
123
124
125
126
127
128
129
130
# File 'lib/relaton_ietf/bibxml_parser.rb', line 122

def full_name(fname, sname, inits, lang, script = nil)
  surname, ints, name = parse_surname_initials fname, sname, inits
  initials = localized_string(ints, lang, script)
  RelatonBib::FullName.new(
    completename: localized_string(fname, lang, script),
    initials: initials, forename: forename(ints, name, lang, script),
    surname: localized_string(surname, lang, script)
  )
end

#full_name_org(name) ⇒ Object

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



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/relaton_ietf/bibxml_parser.rb', line 70

def full_name_org(name) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
  case name
  when "ISO"
    RelatonBib::Organization.new(abbreviation: name, name: "International Organization for Standardization")
  when "IAB"
    RelatonBib::Organization.new(abbreviation: name, name: "Internet Architecture Board")
  when "IESG"
    RelatonBib::Organization.new(abbreviation: name, name: "Internet Engineering Steering Group")
  when "IANA"
    RelatonBib::Organization.new(abbreviation: name, name: "Internet Assigned Numbers Authority")
  when "International Organization for Standardization"
    RelatonBib::Organization.new(abbreviation: "ISO", name: 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
    RelatonBib::Organization.new(abbreviation: abbr, name: name)
  when "IETF Secretariat"
    RelatonBib::Organization.new(abbreviation: "IETF", name: 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."
    RelatonBib::Organization.new(name: name)
  when "Internet Assigned Numbers Authority (IANA)"
    RelatonBib::Organization.new(abbreviation: "IANA", name: "Internet Assigned Numbers Authority (IANA)")
  when "ESnet Site Coordinating Comittee (ESCC)"
    RelatonBib::Organization.new(abbreviation: "ESCC", name: "ESnet Site Coordinating Comittee (ESCC)")
  when "Energy Sciences Network (ESnet)"
    RelatonBib::Organization.new(abbreviation: "ESnet", name: "Energy Sciences Network (ESnet)")
  when "International Telegraph and Telephone Consultative Committee of the International Telecommunication Union"
    RelatonBib::Organization.new(abbreviation: "CCITT", name: name)
  end
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



161
162
163
164
165
166
167
# File 'lib/relaton_ietf/bibxml_parser.rb', line 161

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

#person(author, reference) ⇒ Object



64
65
66
67
68
# File 'lib/relaton_ietf/bibxml_parser.rb', line 64

def person(author, reference)
  return unless author[:fullname] && author[:fullname] != "None"

  full_name_org(author[:fullname]) || super
end

#pubid_type(id) ⇒ String

Extract document identifier type form identifier

Parameters:

  • id (String)

    identifier

Returns:

  • (String)

    type



36
37
38
39
40
41
42
43
# File 'lib/relaton_ietf/bibxml_parser.rb', line 36

def pubid_type(id)
  type = super
  case type
  when "BCP", "FYI", "STD", "RFC" then "RFC"
  when "I-D" then "Internet-Draft"
  else "IETF"
  end
end