Class: RelatonIetf::RfcIndexEntry

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, doc_id, is_also) ⇒ RfcIndexEntry

Document parser initalization

Parameters:

  • doc (Nokogiri::XML::Element)

    document

  • doc_id (String)

    document id

  • is_also (Array<String>)

    included document ids



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

def initialize(doc, doc_id, is_also)
  @doc = doc
  @name = doc.name.split("-").first
  @shortnum = doc_id[-4..].sub(/^0+/, "")
  @doc_id = doc_id
  @is_also = is_also
end

Class Method Details

.parse(doc) ⇒ RelatonIetf::IetfBibliographicItem?

Initialize document parser and run it

Parameters:

  • doc (Nokogiri::XML::Element)

    document

Returns:



25
26
27
28
29
30
31
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 25

def self.parse(doc)
  doc_id = doc.at("./xmlns:doc-id")
  is_also = doc.xpath("./xmlns:is-also/xmlns:doc-id").map &:text
  return unless doc_id && is_also.any?

  new(doc, doc_id.text, is_also).parse
end

Instance Method Details

#anchorString

Create anchor

Returns:

  • (String)

    anchor



95
96
97
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 95

def anchor
  "#{@name.upcase}#{@shortnum}"
end

#docnumberStrinng

Document number

Returns:

  • (Strinng)

    document number



68
69
70
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 68

def docnumber
  @doc_id
end

#formattedrefRelatonBib::FormattedRef

Create formatted reference

Returns:

  • (RelatonBib::FormattedRef)


113
114
115
116
117
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 113

def formattedref
  RelatonBib::FormattedRef.new(
    content: anchor, language: "en", script: "Latn",
  )
end

#make_titleObject



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

def make_title
  t = case @name
      when "bcp" then "Best Current Practice #{@shortnum}"
      when "fyi" then "For Your Information #{@shortnum}"
      when "std" then "Internet Standard technical specification #{@shortnum}"
      end
  [RelatonBib::TypedTitleString.new(content: t, language: "en", script: "Latn")]
end

#parseRelatonIetf::IetfBibliographicItem

Parse document

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 38

def parse # rubocop:disable Metrics/MethodLength
  IetfBibliographicItem.new(
    title: make_title,
    docnumber: docnumber,
    type: "standard",
    docid: parse_docid,
    language: ["en"],
    script: ["Latn"],
    link: parse_link,
    formattedref: formattedref,
    relation: parse_relation,
    series: parse_series,
    stream: @doc.at("./xmlns:stream")&.text,
  )
end

#parse_docidArray<RelatonBib::DocumentIdentifier>

Create docidentifiers

Returns:

  • (Array<RelatonBib::DocumentIdentifier>)

    docidentifiers



77
78
79
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 77

def parse_docid
  [RelatonBib::DocumentIdentifier.new(type: "IETF", id: pub_id, primary: true)]
end

Create link

Returns:

  • (Array<RelatonBib::TypedUri>)


104
105
106
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 104

def parse_link
  [RelatonBib::TypedUri.new(type: "src", content: "https://www.rfc-editor.org/info/#{@name}#{@shortnum}")]
end

#parse_relationArray<Hash>

Create relations

Returns:

  • (Array<Hash>)

    relations



124
125
126
127
128
129
130
131
132
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 124

def parse_relation
  @is_also.map do |ref|
    fref = RelatonBib::FormattedRef.new content: ref
    id = ref.sub(/^([A-Z]+)0*(\d+)$/, '\1 \2')
    docid = RelatonBib::DocumentIdentifier.new(type: "IETF", id: id, primary: true)
    bib = IetfBibliographicItem.new formattedref: fref, docid: [docid]
    { type: "includes", bibitem: bib }
  end
end

#parse_seriesObject



134
135
136
137
138
139
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 134

def parse_series
  @doc.xpath("./xmlns:stream").map do |s|
    title = RelatonBib::TypedTitleString.new content: s.text
    RelatonBib::Series.new type: "stream", title: title
  end
end

#pub_idString

Create pub_id

Returns:

  • (String)

    pub_id



86
87
88
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 86

def pub_id
  "#{@name.upcase} #{@shortnum}"
end