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..-1].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



97
98
99
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 97

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

#docnumberStrinng

Document number

Returns:

  • (Strinng)

    document number



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

def docnumber
  @doc_id
end

#formattedrefRelatonBib::FormattedRef

Create formatted reference

Returns:

  • (RelatonBib::FormattedRef)


115
116
117
118
119
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 115

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

#make_titleObject



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

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
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 38

def parse # rubocop:disable Metrics/MethodLength
  IetfBibliographicItem.new(
    fetched: Date.today.to_s,
    title: make_title,
    docnumber: docnumber,
    type: "standard",
    docid: parse_docid,
    language: ["en"],
    script: ["Latn"],
    link: parse_link,
    formattedref: formattedref,
    relation: parse_relation,
  )
end

#parse_docidArray<RelatonBib::DocumentIdentifier>

Create docidentifiers

Returns:

  • (Array<RelatonBib::DocumentIdentifier>)

    docidentifiers



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

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

Create link

Returns:

  • (Array<RelatonBib::TypedUri>)


106
107
108
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 106

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



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

def parse_relation
  @is_also.map do |ref|
    fref = RelatonBib::FormattedRef.new content: ref
    docid = RelatonBib::DocumentIdentifier.new(type: "IETF", id: ref, primary: true)
    bib = IetfBibliographicItem.new formattedref: fref, docid: [docid]
    { type: "includes", bibitem: bib }
  end
end

#pub_idString

Create pub_id

Returns:

  • (String)

    pub_id



88
89
90
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 88

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