lib/ecoportal/api/common/content/string_digest.rb in ecoportal-api-oozes-0.5.8 vs lib/ecoportal/api/common/content/string_digest.rb in ecoportal-api-oozes-0.5.9

- old
+ new

@@ -5,15 +5,20 @@ module Common module Content module StringDigest MAX_HASH_LABEL = 64 + def indexable_label(str) + return nil unless str + lbl = str.downcase.gsub(/[^A-Za-z]+/,"-").slice(0, MAX_HASH_LABEL) + return nil unless lbl.length >= 3 + lbl + end + # Calculates the Hash of the field based on label def hash_label(str) - return false unless str - label = str.downcase.gsub(/[^A-Za-z]+/,"-").slice(0, MAX_HASH_LABEL) - return false unless label.length >= 3 - return "z" + Digest::MD5.hexdigest(label).slice(0, 8); + return nil unless lbl = indexable_label(str) + "z" + Digest::MD5.hexdigest(lbl).slice(0, 8); end end end end