Class: RelatonIetf::RfcEntry
- Inherits:
-
Object
- Object
- RelatonIetf::RfcEntry
- Defined in:
- lib/relaton_ietf/rfc_entry.rb
Class Method Summary collapse
-
.parse(doc) ⇒ RelatonIetf::IetfBibliographicItem
Initialize parser & parse document.
Instance Method Summary collapse
-
#code ⇒ String
Parse document code.
-
#initialize(doc) ⇒ RfcEntry
constructor
Initalize parser.
-
#parse ⇒ RelatonIetf::IetfBibliographicItem
Parse document.
-
#parse_abstract ⇒ Array<RelatonBib::FormattedString>
Parse document abstract.
-
#parse_contributor ⇒ Array<RelatonBib::ContributionInfo>
Parse document contributors.
-
#parse_date ⇒ Array<RelatonBib::BibliographicDate>
Parse document date.
-
#parse_docid ⇒ Array<RelatonBib::DocumentIdettifier>
Parse document identifiers.
-
#parse_editorialgroup ⇒ RelatonBib::EditorialGroup
Parse document editorial group.
-
#parse_keyword ⇒ Array<String>
Parse document keywords.
-
#parse_link ⇒ Array<RelatonBib::TypedUri>
Create link.
-
#parse_relation ⇒ Arra<RelatonBib::DocumentRelation>
Parse document relations.
-
#parse_status ⇒ RelatonBib::DocuemntStatus
Parse document status.
-
#parse_title ⇒ Array<RelatonBib::TypedTileString>
Parse document title.
-
#pub_id ⇒ String
Create PubID.
Constructor Details
#initialize(doc) ⇒ RfcEntry
Initalize parser
8 9 10 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 8 def initialize(doc) @doc = doc end |
Class Method Details
.parse(doc) ⇒ RelatonIetf::IetfBibliographicItem
Initialize parser & parse document
19 20 21 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 19 def self.parse(doc) new(doc).parse end |
Instance Method Details
#code ⇒ String
Parse document code
84 85 86 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 84 def code @doc.at("./xmlns:doc-id").text end |
#parse ⇒ RelatonIetf::IetfBibliographicItem
Parse document
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 28 def parse # rubocop:disable Metrics/MethodLength IetfBibliographicItem.new( type: "standard", language: ["en"], script: ["Latn"], fetched: Date.today.to_s, docid: parse_docid, docnumber: code, title: parse_title, link: parse_link, date: parse_date, contributor: parse_contributor, keyword: parse_keyword, abstract: parse_abstract, relation: parse_relation, status: parse_status, editorialgroup: parse_editorialgroup, ) end |
#parse_abstract ⇒ Array<RelatonBib::FormattedString>
Parse document abstract
142 143 144 145 146 147 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 142 def parse_abstract @doc.xpath("./xmlns:abstract").map do |c| RelatonBib::FormattedString.new(content: c.text, language: "en", script: "Latn", format: "text/html") end end |
#parse_contributor ⇒ Array<RelatonBib::ContributionInfo>
Parse document contributors
118 119 120 121 122 123 124 125 126 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 118 def parse_contributor @doc.xpath("./xmlns:author").map do |contributor| n = contributor.at("./xmlns:name").text name = RelatonBib::LocalizedString.new( n, "en", "Latn") fname = RelatonBib::FullName.new(completename: name) person = RelatonBib::Person.new(name: fname) RelatonBib::ContributionInfo.new(entity: person, role: [{ type: "author" }]) end end |
#parse_date ⇒ Array<RelatonBib::BibliographicDate>
Parse document date
104 105 106 107 108 109 110 111 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 104 def parse_date @doc.xpath("./xmlns:date").map do |date| month = date.at("./xmlns:month").text year = date.at("./xmlns:year").text on = "#{year}-#{Date::MONTHNAMES.index(month).to_s.rjust(2, '0')}" RelatonBib::BibliographicDate.new(on: on, type: "published") end end |
#parse_docid ⇒ Array<RelatonBib::DocumentIdettifier>
Parse document identifiers
53 54 55 56 57 58 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 53 def parse_docid ids = [RelatonBib::DocumentIdentifier.new(id: pub_id, type: "IETF")] doi = @doc.at("./xmlns:doi").text ids << RelatonBib::DocumentIdentifier.new(id: doi, type: "DOI") ids end |
#parse_editorialgroup ⇒ RelatonBib::EditorialGroup
Parse document editorial group
178 179 180 181 182 183 184 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 178 def parse_editorialgroup tc = @doc.xpath("./xmlns:wg_acronym").map do |wg| wg = RelatonBib::WorkGroup.new(name: wg.text) RelatonBib::TechnicalCommittee.new(wg) end RelatonBib::EditorialGroup.new(tc) end |
#parse_keyword ⇒ Array<String>
Parse document keywords
133 134 135 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 133 def parse_keyword @doc.xpath("./xmlns:keywords/xmlns:kw").map &:text end |
#parse_link ⇒ Array<RelatonBib::TypedUri>
Create link
93 94 95 96 97 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 93 def parse_link num = code[-4..-1].sub(/^0+/, "") url = "https://www.rfc-editor.org/info/rfc#{num}" [RelatonBib::TypedUri.new(content: url, type: "src")] end |
#parse_relation ⇒ Arra<RelatonBib::DocumentRelation>
Parse document relations
154 155 156 157 158 159 160 161 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 154 def parse_relation types = { "updates" => "updates", "obsoleted-by" => "obsoletedBy"} @doc.xpath("./xmlns:updates/xmlns:doc-id|./xmlns:obsoleted-by/xmlns:doc-id").map do |r| fref = RelatonBib::FormattedRef.new(content: r.text) bib = IetfBibliographicItem.new(formattedref: fref) RelatonBib::DocumentRelation.new(type: types[r.parent.name], bibitem: bib) end end |
#parse_status ⇒ RelatonBib::DocuemntStatus
Parse document status
168 169 170 171 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 168 def parse_status stage = @doc.at("./xmlns:current-status").text RelatonBib::DocumentStatus.new(stage: stage) end |
#parse_title ⇒ Array<RelatonBib::TypedTileString>
Parse document title
65 66 67 68 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 65 def parse_title content = @doc.at("./xmlns:title").text [RelatonBib::TypedTitleString.new(content: content, type: "main")] end |
#pub_id ⇒ String
Create PubID
75 76 77 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 75 def pub_id "IETF #{code.sub(/^(RFC)(\d+)/, '\1 \2')}" end |