Module: Dapp::Dapp::Slug
- Included in:
- Dapp::Dapp
- Defined in:
- lib/dapp/dapp/slug.rb
Instance Method Summary collapse
- #consistent_uniq_slug_reg ⇒ Object
- #consistent_uniq_slugify(s) ⇒ Object
- #should_be_slugged?(s) ⇒ Boolean
Instance Method Details
#consistent_uniq_slug_reg ⇒ Object
20 21 22 |
# File 'lib/dapp/dapp/slug.rb', line 20 def consistent_uniq_slug_reg /(?!-)((-?[a-z0-9]+)+)(?<!-)/ end |
#consistent_uniq_slugify(s) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/dapp/dapp/slug.rb', line 4 def consistent_uniq_slugify(s) if should_be_slugged?(s) consistent_uniq_slug_reg =~ s.gsub("/", "-").slugify.squeeze('--') [].tap do |slug| slug << Regexp.last_match(1) unless Regexp.last_match(1).nil? slug << MurmurHash3::V32.str_hexdigest(s) end.compact.join('-') else s end end |
#should_be_slugged?(s) ⇒ Boolean
16 17 18 |
# File 'lib/dapp/dapp/slug.rb', line 16 def should_be_slugged?(s) !(/^#{consistent_uniq_slug_reg}$/ =~ s) end |