Class: SimpleSlugs::Slug
Instance Method Summary collapse
- #class ⇒ Object
- #dasherize! ⇒ Object
-
#initialize(string) ⇒ Slug
constructor
A new instance of Slug.
- #join_spaces! ⇒ Object
- #normalize ⇒ Object
- #spacify! ⇒ Object
- #transliterate! ⇒ Object
Methods inherited from String
Constructor Details
#initialize(string) ⇒ Slug
Returns a new instance of Slug.
6 7 8 9 |
# File 'lib/simple_slugs/slug.rb', line 6 def initialize(string) super normalize end |
Instance Method Details
#class ⇒ Object
11 12 13 |
# File 'lib/simple_slugs/slug.rb', line 11 def class String end |
#dasherize! ⇒ Object
36 37 38 |
# File 'lib/simple_slugs/slug.rb', line 36 def dasherize! gsub!(' ', '-') end |
#join_spaces! ⇒ Object
32 33 34 |
# File 'lib/simple_slugs/slug.rb', line 32 def join_spaces! gsub!(/\s+/, ' ') end |
#normalize ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/simple_slugs/slug.rb', line 15 def normalize transliterate! spacify! join_spaces! strip! downcase! dasherize! end |
#spacify! ⇒ Object
28 29 30 |
# File 'lib/simple_slugs/slug.rb', line 28 def spacify! gsub!(/[\W_]/, ' ') end |
#transliterate! ⇒ Object
24 25 26 |
# File 'lib/simple_slugs/slug.rb', line 24 def transliterate! replace(I18n.transliterate(self)) end |