lib/commonmeta/utils.rb in commonmeta-ruby-3.3 vs lib/commonmeta/utils.rb in commonmeta-ruby-3.3.1

- old
+ new

@@ -1382,14 +1382,17 @@ }.compact] end end def encode_doi(prefix, options = {}) + return nil unless prefix.present? + # DOI suffix is a generated from a random number, encoded in base32 # suffix has 8 digits plus two checksum digits. With base32 there are # 32 possible digits, so 8 digits gives 32^8 possible combinations if options[:uuid] str = Base32::URL.encode_uuid(options[:uuid], split: 7, checksum: true) + return nil unless str.present? else random_int = SecureRandom.random_number(32 ** 7..(32 ** 8) - 1) suffix = Base32::URL.encode(random_int, checksum: true) str = "#{suffix[0, 5]}-#{suffix[5, 10]}" end