Module: Ecoportal::API::Common::Content::StringDigest
- Included in:
- V2::Page::Component
- Defined in:
- lib/ecoportal/api/common/content/string_digest.rb
Constant Summary collapse
- MAX_HASH_LABEL =
64
Instance Method Summary collapse
-
#hash_label(str, any_length: false) ⇒ Object
Calculates the Hash of the field based on label.
- #indexable_label(str, any_length: false) ⇒ Object
Instance Method Details
#hash_label(str, any_length: false) ⇒ Object
Calculates the Hash of the field based on label
18 19 20 21 |
# File 'lib/ecoportal/api/common/content/string_digest.rb', line 18 def hash_label(str, any_length: false) return nil unless lbl = indexable_label(str, any_length: any_length) "z" + Digest::MD5.hexdigest(lbl).slice(0, 8); end |
#indexable_label(str, any_length: false) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/ecoportal/api/common/content/string_digest.rb', line 10 def indexable_label(str, any_length: false) return nil unless str lbl = str.downcase.gsub(/[^A-Za-z]+/,"-").slice(0, MAX_HASH_LABEL) return nil if (lbl.length < 3) && !any_length lbl end |