lib/relaton_nist/data_fetcher.rb in relaton-nist-1.13.0 vs lib/relaton_nist/data_fetcher.rb in relaton-nist-1.13.1

- old
+ new

@@ -172,22 +172,25 @@ # @param [Nokogiri::XML::Element] person person name element # @param [Nokogiri::XML::Element] doc document element # # @return [Array<Array<RelatonBib::LocalizedString>>] forename and initials # - def forename_initial(person, doc) # rubocop:disable Metrics/MethodLength + def forename_initial(person, doc) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity fnames = [] fname = person.at("given_name")&.text if fname if /^(?<inits>(?:\w[.\s]+|[A-Z]{1,2}$)+)$/ =~ fname ints = inits.split(/[.\s]*/) fnames << forename(doc, fname, ints.shift) ints.each { |i| fnames << forename(doc, nil, i) } - else fnames << forename(doc, fname) + else + fn = forename(doc, fname) + fnames << fn if fn end end - [fnames, localized_string(inits, doc)] + initials = localized_string inits, doc if not(inits.nil? || inits.empty?) + [fnames, initials] end # # Create forename object # @@ -196,9 +199,11 @@ # @param [String, nil] init initial content # # @return [RelatonBib::Forename] forename object # def forename(doc, cnt, init = nil) + return if (cnt.nil? || cnt.empty?) && (init.nil? || init.empty?) + RelatonBib::Forename.new( content: cnt, language: doc["language"], script: "Latn", initial: init, ) end