lib/relaton_nist/data_fetcher.rb in relaton-nist-1.11.2 vs lib/relaton_nist/data_fetcher.rb in relaton-nist-1.11.3
- old
+ new
@@ -156,24 +156,41 @@
)
person = RelatonBib::Person.new name: fullname, affiliation: affiliation(doc)
{ entity: person, role: [{ type: p["contributor_role"] }] }
end
contribs + doc.xpath("publisher").map do |p|
- abbr = p.at("../institution/institution_acronym")&.text
- place = p.at("./publisher_place")
- cont = []
- if place
- city, state = place.text.split(", ")
- cont << RelatonBib::Address.new(street: [], city: city, state: state, country: "US")
- end
- org = RelatonBib::Organization.new(
- name: p.at("publisher_name").text, abbreviation: abbr, contact: cont,
- )
- { entity: org, role: [{ type: "publisher" }] }
+ { entity: create_org(p), role: [{ type: "publisher" }] }
end
end
+ #
+ # Create publisher organization
+ #
+ # @param [Nokogiri::XML::Element] pub publisher element
+ #
+ # @return [RelatonBib::Organization] publisher organization
+ #
+ def create_org(pub)
+ name = pub.at("publisher_name").text
+ abbr = pub.at("../institution[institution_name[.='#{name}']]/institution_acronym")&.text
+ place = pub.at("./publisher_place") ||
+ pub.at("../institution[institution_name[.='#{name}']]/institution_place")
+ cont = []
+ if place
+ city, state = place.text.split(", ")
+ cont << RelatonBib::Address.new(street: [], city: city, state: state, country: "US")
+ end
+ RelatonBib::Organization.new name: name, abbreviation: abbr, contact: cont
+ end
+
+ #
+ # Create affiliation organization
+ #
+ # @param [Nokogiri::XML::Element] doc affiliation element
+ #
+ # @return [Array<RelatonBib::Affiliation>] affiliation
+ #
def affiliation(doc)
doc.xpath("./institution/institution_department").map do |id|
org = RelatonBib::Organization.new name: id.text
RelatonBib::Affiliation.new organization: org
end
@@ -183,12 +200,23 @@
# @return [Array<String>]
def fetch_place(doc)
doc.xpath("institution/institution_place").map(&:text)
end
+ #
+ # Fetches series
+ #
+ # @param [Nokogiri::XML::Element] doc document element
+ #
+ # @return [Array<RelatonBib::Series>] series
+ #
def fetch_series(doc)
- title = RelatonBib::TypedTitleString.new(content: "NIST")
- [RelatonBib::Series.new(title: title, number: pub_id(doc))]
+ series_path = File.expand_path("series.yaml", __dir__)
+ series = YAML.load_file series_path
+ prf, srs, = pub_id(doc).split
+ sname = series[srs] || srs
+ title = RelatonBib::TypedTitleString.new(content: "#{prf} #{sname}")
+ [RelatonBib::Series.new(title: title, number: "#{prf} #{srs}")]
end
#
# Save document
#