class IETFBib::XMLParser
Public Class Methods
from_xml(xml)
click to toggle source
# File lib/ietfbib/xml_parser.rb, line 6 def from_xml(xml) doc = Nokogiri::XML(xml) IsoBibItem::BibliographicItem.new( id: fetch_id(doc), 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), 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), series: fetch_series(doc) ) end
Private Class Methods
fetch_id(doc)
click to toggle source
# File lib/ietfbib/xml_parser.rb, line 30 def fetch_id(doc) doc.at('/bibitem')[:id] end
fetch_series(doc)
click to toggle source
# File lib/ietfbib/xml_parser.rb, line 40 def fetch_series(doc) doc.xpath('/bibitem/series').map do |s| t = s.at('./title') title = IsoBibItem::FormattedString.new( content: t.text, language: t[:language], type: t[:format], script: t[:script] ) abbr = s.at('./abbreviation') abbr = IsoBibItem::LocalizedString.new(abbr.text) if abbr IsoBibItem::Series.new( title: title, type: s[:type], place: s.at('./place')&.text, organization: s.at('./organization')&.text, abbreviation: abbr, from: s.at('./from')&.text, to: s.at('./to')&.text, number: s.at('./number')&.text, part_number: s.at('./part_numper')&.text ) end end
fetch_titles(doc)
click to toggle source
# File lib/ietfbib/xml_parser.rb, line 34 def fetch_titles(doc) doc.xpath('/bibitem/title').map do |t| { content: t.text, language: t[:language], script: t[:script] } end end