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.
- #create_org_contrib(org_name, role_type) ⇒ Object
-
#docnum ⇒ String
Parse document number.
-
#forename(int) ⇒ Array<RelatonBib::Forename>
Ctreat initials.
-
#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_role(contrib) ⇒ Array<Hash>
Parse contributors role.
-
#parse_series ⇒ Array<RelatonBib::Series>
Parse series.
-
#parse_status ⇒ RelatonBib::DocuemntStatus
Parse document status.
-
#parse_title ⇒ Array<RelatonBib::TypedTileString>
Parse document title.
-
#pub_id ⇒ String
Create PubID.
- #seires_stream ⇒ Object
- #series_is_also ⇒ Object
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
122 123 124 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 122 def code @doc.at("./xmlns:doc-id").text end |
#create_org_contrib(org_name, role_type) ⇒ Object
178 179 180 181 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 178 def create_org_contrib(org_name, role_type) org = RelatonBib::Organization.new name: org_name RelatonBib::ContributionInfo.new entity: org, role: [{ type: role_type }] end |
#docnum ⇒ String
Parse document number
113 114 115 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 113 def docnum /\d+$/.match(code).to_s.sub(/^0+/, "") end |
#forename(int) ⇒ Array<RelatonBib::Forename>
Ctreat initials
203 204 205 206 207 208 209 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 203 def forename(int) return [] unless int int.split(/\.-?\s?|\s/).map do |i| RelatonBib::Forename.new initial: i, language: "en", script: "Latn" end 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 47 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 28 def parse # rubocop:disable Metrics/MethodLength IetfBibliographicItem.new( type: "standard", language: ["en"], script: ["Latn"], 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, series: parse_series, stream: @doc.at("./xmlns:stream")&.text, editorialgroup: parse_editorialgroup, ) end |
#parse_abstract ⇒ Array<RelatonBib::FormattedString>
Parse document abstract
225 226 227 228 229 230 231 232 233 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 225 def parse_abstract @doc.xpath("./xmlns:abstract").map do |c| content = c.xpath("./xmlns:p").map do |p| "<#{p.name}>#{p.text.strip}</#{p.name}>" end.join RelatonBib::FormattedString.new(content: content, language: "en", script: "Latn", format: "text/html") end end |
#parse_contributor ⇒ Array<RelatonBib::ContributionInfo>
Parse document contributors
164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 164 def parse_contributor # rubocop:disable Metrics/MethodLength contribs = @doc.xpath("./xmlns:author").map do |contrib| name = contrib.at("./xmlns:name").text entity = BibXMLParser.full_name_org name unless entity fname = BibXMLParser.full_name name, nil, nil, "en", "Latn" entity = RelatonBib::Person.new(name: fname) end RelatonBib::ContributionInfo.new(entity: entity, role: parse_role(contrib)) end contribs << create_org_contrib("RFC Publisher", "publisher") contribs << create_org_contrib("RFC Series", "authorizer") end |
#parse_date ⇒ Array<RelatonBib::BibliographicDate>
Parse document date
150 151 152 153 154 155 156 157 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 150 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
79 80 81 82 83 84 85 86 87 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 79 def parse_docid ids = [ RelatonBib::DocumentIdentifier.new(id: pub_id, type: "IETF", primary: true), # RelatonBib::DocumentIdentifier.new(id: anchor, type: "IETF", scope: "anchor"), ] doi = @doc.at("./xmlns:doi").text ids << RelatonBib::DocumentIdentifier.new(id: doi, type: "DOI") ids end |
#parse_editorialgroup ⇒ RelatonBib::EditorialGroup
Parse document editorial group
265 266 267 268 269 270 271 272 273 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 265 def parse_editorialgroup tc = @doc.xpath("./xmlns:wg_acronym").each_with_object([]) do |wg, arr| next if wg.text == "NON WORKING GROUP" wg = RelatonBib::WorkGroup.new(name: wg.text) arr << RelatonBib::TechnicalCommittee.new(wg) end RelatonBib::EditorialGroup.new(tc) if tc.any? end |
#parse_keyword ⇒ Array<String>
Parse document keywords
216 217 218 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 216 def parse_keyword @doc.xpath("./xmlns:keywords/xmlns:kw").map &:text end |
#parse_link ⇒ Array<RelatonBib::TypedUri>
Create link
140 141 142 143 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 140 def parse_link url = "https://www.rfc-editor.org/info/rfc#{docnum}" [RelatonBib::TypedUri.new(content: url, type: "src")] end |
#parse_relation ⇒ Arra<RelatonBib::DocumentRelation>
Parse document relations
240 241 242 243 244 245 246 247 248 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 240 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) docid = RelatonBib::DocumentIdentifier.new type: "IETF", id: r.text, primary: true bib = IetfBibliographicItem.new(formattedref: fref, docid: [docid]) RelatonBib::DocumentRelation.new(type: types[r.parent.name], bibitem: bib) end end |
#parse_role(contrib) ⇒ Array<Hash>
Parse contributors role
190 191 192 193 194 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 190 def parse_role(contrib) type = contrib.at("./xmlns:title")&.text&.downcase || "author" role = { type: type } [role] end |
#parse_series ⇒ Array<RelatonBib::Series>
Parse series
54 55 56 57 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 54 def parse_series title = RelatonBib::TypedTitleString.new(content: "RFC") series_is_also + [RelatonBib::Series.new(title: title, number: docnum)] + seires_stream end |
#parse_status ⇒ RelatonBib::DocuemntStatus
Parse document status
255 256 257 258 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 255 def parse_status stage = @doc.at("./xmlns:current-status").text RelatonBib::DocumentStatus.new(stage: stage) end |
#parse_title ⇒ Array<RelatonBib::TypedTileString>
Parse document title
94 95 96 97 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 94 def parse_title content = @doc.at("./xmlns:title").text [RelatonBib::TypedTitleString.new(content: content, type: "main")] end |
#pub_id ⇒ String
Create PubID
104 105 106 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 104 def pub_id "RFC #{docnum}" end |
#seires_stream ⇒ Object
67 68 69 70 71 72 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 67 def seires_stream @doc.xpath("./xmlns:stream").map do |s| t = RelatonBib::TypedTitleString.new content: s.text RelatonBib::Series.new type: "stream", title: t end end |
#series_is_also ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/relaton_ietf/rfc_entry.rb', line 59 def series_is_also @doc.xpath("./xmlns:is-also/xmlns:doc-id").map do |s| /^(?<name>\D+)(?<num>\d+)/ =~ s.text t = RelatonBib::TypedTitleString.new(content: name) RelatonBib::Series.new title: t, number: num.gsub(/^0+/, "") end end |