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(name, doc_id, is_also) ⇒ RfcIndexEntry

Document parser initalization

Parameters:

  • name (String)

    document type name

  • doc_id (String)

    document id

  • is_also (Array<String>)

    included document ids



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

def initialize(name, doc_id, is_also)
  @name = name
  @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:

  • (RelatonIetf:IetfBibliographicItem, nil)


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

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?

  name = doc.name.split("-").first
  new(name, doc_id.text, is_also).parse
end

Instance Method Details

#anchorObject



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

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

#docnumberStrinng

Document id

Returns:

  • (Strinng)

    document id



51
52
53
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 51

def docnumber
  @doc_id
end

#formattedrefObject



74
75
76
77
78
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 74

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

#parseObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 33

def parse
  IetfBibliographicItem.new(
    docnumber: docnumber,
    type: "standard",
    docid: parse_docid,
    language: ["en"],
    script: ["Latn"],
    link: parse_link,
    formattedref: formattedref,
    relation: parse_relation,
  )
end

#parse_docidObject



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

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


70
71
72
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 70

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

#parse_relationObject



80
81
82
83
84
85
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 80

def parse_relation
  @is_also.map do |ref|
    bib = IetfBibliography.get ref.sub(/^(RFC)(\d+)/, '\1 \2')
    { type: "includes", bibitem: bib }
  end
end

#pub_idObject



62
63
64
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 62

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