Module: Dapp::Dapp::Slug::V3
- Defined in:
- lib/dapp/dapp/slug.rb
Instance Method Summary collapse
- #consistent_uniq_slug(s) ⇒ Object
- #consistent_uniq_slugify(s) ⇒ Object
- #should_be_slugged?(s) ⇒ Boolean
Instance Method Details
#consistent_uniq_slug(s) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/dapp/dapp/slug.rb', line 61 def consistent_uniq_slug(s) ''.tap do |res| status = :empty s.to_s.chars.each do |ch| next if (s_ch = ch.slugify).empty? if s_ch !~ /[[:punct:]|[:blank:]]/ res << s_ch status = :non_empty if status == :empty elsif status == :non_empty && res[-1] != '-' res << '-' end end end.chomp('-') end |
#consistent_uniq_slugify(s) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dapp/dapp/slug.rb', line 42 def consistent_uniq_slugify(s) return s unless should_be_slugged?(s) slug = consistent_uniq_slug(s) murmur_hash = MurmurHash3::V32.str_hexdigest(s) [].tap do |res| res << begin unless slug.empty? index = SLUG_V2_LIMIT_LENGTH - murmur_hash.length - SLUG_SEPARATOR.length - 1 slug[0..index] end end res << murmur_hash end.compact.join(SLUG_SEPARATOR) end |
#should_be_slugged?(s) ⇒ Boolean
57 58 59 |
# File 'lib/dapp/dapp/slug.rb', line 57 def should_be_slugged?(s) consistent_uniq_slug(s) != s || s.length > SLUG_V2_LIMIT_LENGTH end |