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.
- #parse_series ⇒ Object
-
#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..].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
95 96 97 |
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 95 def anchor "#{@name.upcase}#{@shortnum}" end |
#docnumber ⇒ Strinng
Document number
68 69 70 |
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 68 def docnumber @doc_id end |
#formattedref ⇒ RelatonBib::FormattedRef
Create formatted reference
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_title ⇒ Object
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 |
#parse ⇒ RelatonIetf::IetfBibliographicItem
Parse document
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_docid ⇒ Array<RelatonBib::DocumentIdentifier>
Create 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 |
#parse_link ⇒ Array<RelatonBib::TypedUri>
Create link
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_relation ⇒ Array<Hash>
Create relations
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 124 def parse_relation @is_also.map do |ref| entry = @doc.at("/xmlns:rfc-index/xmlns:rfc-entry[xmlns:doc-id = '#{ref}']") bib = RfcEntry.parse entry # 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_series ⇒ Object
136 137 138 139 140 141 |
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 136 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_id ⇒ String
Create pub_id
86 87 88 |
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 86 def pub_id "#{@name.upcase} #{@shortnum}" end |