Class: RelatonIana::Parser
- Inherits:
-
Object
- Object
- RelatonIana::Parser
- Defined in:
- lib/relaton_iana/parser.rb
Class Method Summary collapse
-
.parse(xml, rootdoc = nil) ⇒ RelatonIana::IanaBibliographicItem?
Initialize document parser and run it.
Instance Method Summary collapse
-
#anchor ⇒ String
Create anchor.
-
#contributor ⇒ Array<RelatonBib::Contribution>
Create contributor.
-
#docnumber ⇒ String
Create docnumber.
-
#initialize(xml, rootdoc) ⇒ Parser
constructor
Document parser initalization.
-
#parse ⇒ RelatonIana::IanaBibliographicItem?
Parse document.
-
#parse_date ⇒ Array<RelatonBib::BibliographicDate>
Parse date.
-
#parse_docid ⇒ Arra<RelatonBib::DocumentIdentifier>
Parse docidentifier.
-
#parse_link ⇒ Array<RelatonBib::TypedUri>
Parse link.
-
#parse_title ⇒ RelatonBib::TypedTitleStringCollection
Parse title.
-
#pub_id ⇒ String
Generate PubID.
Constructor Details
#initialize(xml, rootdoc) ⇒ Parser
Document parser initalization
8 9 10 11 |
# File 'lib/relaton_iana/parser.rb', line 8 def initialize(xml, rootdoc) @xml = xml @rootdoc = rootdoc end |
Class Method Details
.parse(xml, rootdoc = nil) ⇒ RelatonIana::IanaBibliographicItem?
Initialize document parser and run it
20 21 22 |
# File 'lib/relaton_iana/parser.rb', line 20 def self.parse(xml, rootdoc = nil) new(xml, rootdoc).parse end |
Instance Method Details
#anchor ⇒ String
Create anchor
83 84 85 |
# File 'lib/relaton_iana/parser.rb', line 83 def anchor docnumber.upcase.gsub("/", "__") end |
#contributor ⇒ Array<RelatonBib::Contribution>
Create contributor
124 125 126 127 128 129 130 |
# File 'lib/relaton_iana/parser.rb', line 124 def contributor org = RelatonBib::Organization.new( name: "Internet Assigned Numbers Authority", abbreviation: "IANA", ) role = { type: "publisher" } [RelatonBib::ContributionInfo.new(entity: org, role: [role])] end |
#docnumber ⇒ String
Create docnumber
101 102 103 104 105 |
# File 'lib/relaton_iana/parser.rb', line 101 def docnumber dn = "" dn += "#{@rootdoc.docnumber}/" if @rootdoc dn + @xml["id"] end |
#parse ⇒ RelatonIana::IanaBibliographicItem?
Parse document
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/relaton_iana/parser.rb', line 29 def parse # rubocop:disable Metrics/MethodLength, Metrics/AbcSize return unless @xml RelatonIana::IanaBibliographicItem.new( type: "standard", language: ["en"], script: ["Latn"], title: parse_title, link: parse_link, docid: parse_docid, docnumber: docnumber, date: parse_date, contributor: contributor, ) end |
#parse_date ⇒ Array<RelatonBib::BibliographicDate>
Parse date
112 113 114 115 116 117 |
# File 'lib/relaton_iana/parser.rb', line 112 def parse_date d = @xml.xpath("./xmlns:created|./xmlns:published|./xmlns:updated").map do |d| RelatonBib::BibliographicDate.new(type: d.name, on: d.text) end d.none? && @rootdoc ? @rootdoc.date : d end |
#parse_docid ⇒ Arra<RelatonBib::DocumentIdentifier>
Parse docidentifier
74 75 76 |
# File 'lib/relaton_iana/parser.rb', line 74 def parse_docid [RelatonBib::DocumentIdentifier.new(type: "IANA", id: pub_id, primary: true)] end |
#parse_link ⇒ Array<RelatonBib::TypedUri>
Parse link
61 62 63 64 65 66 67 |
# File 'lib/relaton_iana/parser.rb', line 61 def parse_link if @rootdoc then @rootdoc.link else uri = URI.join "https://www.iana.org/assignments/", @xml[:id] [RelatonBib::TypedUri.new(type: "self", content: uri.to_s)] end end |
#parse_title ⇒ RelatonBib::TypedTitleStringCollection
Parse title
50 51 52 53 54 |
# File 'lib/relaton_iana/parser.rb', line 50 def parse_title content = @xml.at("./xmlns:title")&.text || @xml[:id] t = RelatonBib::TypedTitleString.new content: content RelatonBib::TypedTitleStringCollection.new [t] end |
#pub_id ⇒ String
Generate PubID
92 93 94 |
# File 'lib/relaton_iana/parser.rb', line 92 def pub_id "IANA #{docnumber}" end |