class RelatonIana::Parser

Public Class Methods

new(xml, rootdoc) click to toggle source

Document parser initalization

@param [Nokogiri::XML::Element] xml

# File lib/relaton_iana/parser.rb, line 8
def initialize(xml, rootdoc)
  @xml = xml
  @rootdoc = rootdoc
end
parse(xml, rootdoc = nil) click to toggle source

Initialize document parser and run it

@param [Nokogiri::XML::Element] xml

@return [RelatonBib:BibliographicItem, nil] bibliographic item

# File lib/relaton_iana/parser.rb, line 20
def self.parse(xml, rootdoc = nil)
  new(xml, rootdoc).parse
end

Public Instance Methods

anchor() click to toggle source

Create anchor

@return [String] anchor

# File lib/relaton_iana/parser.rb, line 87
def anchor
  docnumber.upcase.gsub("/", "__")
end
contributor() click to toggle source

Create contributor

@return [Array<RelatonBib::Contribution>] contributor

# File lib/relaton_iana/parser.rb, line 128
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() click to toggle source

Create docnumber

@return [String] docnumber

# File lib/relaton_iana/parser.rb, line 105
def docnumber
  dn = ""
  dn += "#{@rootdoc.docnumber}/" if @rootdoc
  dn + @xml["id"]
end
parse() click to toggle source

Parse document

@return [RelatonBib:BibliographicItem, nil] bibliographic item

# File lib/relaton_iana/parser.rb, line 29
def parse # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  return unless @xml

  RelatonBib::BibliographicItem.new(
    type: "standard",
    fetched: Date.today.to_s,
    language: ["en"],
    script: ["Latn"],
    title: parse_title,
    link: parse_link,
    docid: parse_docid,
    docnumber: docnumber,
    date: parse_date,
    contributor: contributor,
  )
end
parse_date() click to toggle source

Parse date

@return [Array<RelatonBib::BibliographicDate>] date

# File lib/relaton_iana/parser.rb, line 116
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() click to toggle source

Parse docidentifier

@return [Arra<RelatonBib::DocumentIdentifier>] docidentifier

# File lib/relaton_iana/parser.rb, line 75
def parse_docid
  [
    RelatonBib::DocumentIdentifier.new(type: "IANA", id: pub_id, primary: true),
    RelatonBib::DocumentIdentifier.new(type: "IETF", id: anchor, scope: "anchor"),
  ]
end
parse_title() click to toggle source

Parse title

@return [RelatonBib::TypedTitleStringCollection] title

# File lib/relaton_iana/parser.rb, line 51
def parse_title
  content = @xml.at("./xmlns:title")&.text || @xml[:id]
  t = RelatonBib::TypedTitleString.new content: content
  RelatonBib::TypedTitleStringCollection.new [t]
end
pub_id() click to toggle source

Generate PubID

@return [String] PubID

# File lib/relaton_iana/parser.rb, line 96
def pub_id
  "IANA #{docnumber}"
end