class Gbbib::XMLParser

Public Class Methods

from_xml(xml) click to toggle source
# File lib/gbbib/xml_parser.rb, line 6
def from_xml(xml)
  doc = Nokogiri::XML(xml)
  GbBibliographicItem.new(
    docid:        fetch_docid(doc),
    edition:      doc.at('/bibitem/edition')&.text,
    language:     doc.xpath('/bibitem/language').map(&:text),
    script:       doc.xpath('/bibitem/script').map(&:text),
    titles:       fetch_titles(doc),
    type:         doc.at('bibitem')&.attr(:type),
    docstatus:    fetch_status(doc),
    ics:          fetch_ics(doc),
    dates:        fetch_dates(doc),
    contributors: fetch_contributors(doc),
    workgroup:    fetch_workgroup(doc),
    abstract:     fetch_abstract(doc),
    copyright:    fetch_copyright(doc),
    link:         fetch_link(doc),
    relations:    fetch_relations(doc),
    committee:    fetch_committee(doc),
    ccs:          fetch_ccs(doc),
    gbtype:       fetch_gbtype(doc)
  )
end

Private Class Methods

fetch_ccs(doc) click to toggle source
# File lib/gbbib/xml_parser.rb, line 43
def fetch_ccs(doc)
  doc.xpath('/bibitem/ccs/code').map &:text
end
fetch_committee(doc) click to toggle source
# File lib/gbbib/xml_parser.rb, line 37
def fetch_committee(doc)
  committee = doc.at '/bibitem/gbcommittee' 
  return nil unless committee
  { type: committee[:type], name: committee.text }
end
fetch_gbtype(doc) click to toggle source
# File lib/gbbib/xml_parser.rb, line 47
def fetch_gbtype(doc)
  gbtype = doc.at '/bibitem/gbtype'
  {
    scope: gbtype&.at('gbscope')&.text,
    prefix: gbtype&.at('gbprefix')&.text,
    mandate: gbtype&.at('gbmandate')&.text
  }
end
get_id(did) click to toggle source

Overrade get_id from IsoBibItem::XMLParser

# File lib/gbbib/xml_parser.rb, line 33
def get_id(did)
  id = did.text.match(/^(?<project>.*?\d+)(?<hyphen>-)?(?(<hyphen>)(?<year>\d*))/)
end