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 ⇒ Object
-
#docnumber ⇒ Strinng
Document id.
- #formattedref ⇒ Object
-
#initialize(name, doc_id, is_also) ⇒ RfcIndexEntry
constructor
Document parser initalization.
- #parse ⇒ Object
- #parse_docid ⇒ Object
- #parse_link ⇒ Object
- #parse_relation ⇒ Object
- #pub_id ⇒ Object
Constructor Details
#initialize(name, doc_id, is_also) ⇒ RfcIndexEntry
Document parser initalization
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
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
#anchor ⇒ Object
66 67 68 |
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 66 def anchor "#{@name.upcase}#{@shortnum}" end |
#docnumber ⇒ Strinng
Document id
51 52 53 |
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 51 def docnumber @doc_id end |
#formattedref ⇒ Object
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 |
#parse ⇒ Object
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_docid ⇒ Object
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 |
#parse_link ⇒ Object
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_relation ⇒ Object
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_id ⇒ Object
62 63 64 |
# File 'lib/relaton_ietf/rfc_index_entry.rb', line 62 def pub_id "#{@name.upcase} #{@shortnum}" end |