Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/turbine-core/ext.rb
Direct Known Subclasses
Instance Method Summary collapse
Instance Method Details
#indents(remove_blanks = false) ⇒ Object
19 20 21 22 |
# File 'lib/turbine-core/ext.rb', line 19 def indents(remove_blanks = false) # clear blank lines and then clear left margin reject { |line| line.blank? && remove_blanks }.map { |line| line.gsub(/^\s+$/, "\n") }.join.margin.strip end |
#make_attr ⇒ Object
15 16 17 |
# File 'lib/turbine-core/ext.rb', line 15 def make_attr self.downcase.to_sym end |
#slugify ⇒ Object
2 3 4 |
# File 'lib/turbine-core/ext.rb', line 2 def slugify self.dup.slugify! end |
#slugify! ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/turbine-core/ext.rb', line 6 def slugify! self.gsub!(/[^\x00-\x7F]+/, '') # Remove non-ASCII (e.g. diacritics). self.gsub!(/[^a-z0-9\-_\+]+/i, '-') # Turn non-slug chars into the separator. self.gsub!(/-{2,}/, '-') # No more than one of the separator in a row. self.gsub!(/^-|-$/, '') # Remove leading/trailing separator. self.downcase! self end |