Class: RelatonIetf::RfcIndexEntry
- Inherits:
-
Object
- Object
- RelatonIetf::RfcIndexEntry
- Defined in:
- lib/relaton_ietf/rfc_index_entry.rb
Class Method Summary collapse
-
.parse(doc) ⇒ RelatonIetf::IetfBibliographicItem?
Initialize document parser and run it.
Instance Method Summary collapse
-
#anchor ⇒ String
Create anchor.
-
#docnumber ⇒ Strinng
Document number.
-
#formattedref ⇒ RelatonBib::FormattedRef
Create formatted reference.
-
#initialize(doc, doc_id, is_also) ⇒ RfcIndexEntry
constructor
Document parser initalization.
- #make_title ⇒ Object
-
#parse ⇒ RelatonIetf::IetfBibliographicItem
Parse document.
-
#parse_docid ⇒ Array<RelatonBib::DocumentIdentifier>
Create docidentifiers.
-
#parse_link ⇒ Array<RelatonBib::TypedUri>
Create link.
-
#parse_relation ⇒ Array<Hash>
Create relations.
-
#pub_id ⇒ String
Create pub_id.
Constructor Details
#initialize(doc, doc_id, is_also) ⇒ RfcIndexEntry
Document parser initalization
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
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
#anchor ⇒ String
Create anchor
97 98 99 |
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 97 def anchor "#{@name.upcase}#{@shortnum}" end |
#docnumber ⇒ Strinng
Document number
67 68 69 |
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 67 def docnumber @doc_id end |
#formattedref ⇒ RelatonBib::FormattedRef
Create formatted reference
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_title ⇒ Object
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 |
#parse ⇒ RelatonIetf::IetfBibliographicItem
Parse document
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_docid ⇒ Array<RelatonBib::DocumentIdentifier>
Create 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 |
#parse_link ⇒ Array<RelatonBib::TypedUri>
Create link
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_relation ⇒ Array<Hash>
Create 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_id ⇒ String
Create pub_id
88 89 90 |
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 88 def pub_id "#{@name.upcase} #{@shortnum}" end |