Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/workarea/ext/freedom_patches/money.rb,
lib/workarea/ext/freedom_patches/string.rb
Direct Known Subclasses
Class Method Summary collapse
- .optionize_seperator_regexes ⇒ Object
-
.optionize_unwanted_chars_regex ⇒ Object
These two methods are to cut down on object allocation.
Instance Method Summary collapse
- #optionize(sep = '-') ⇒ Object (also: #slugify, #systemize)
Class Method Details
.optionize_seperator_regexes ⇒ Object
12 13 14 |
# File 'lib/workarea/ext/freedom_patches/string.rb', line 12 def self.optionize_seperator_regexes @optionize_seperator_regexes ||= {} end |
.optionize_unwanted_chars_regex ⇒ Object
These two methods are to cut down on object allocation
8 9 10 |
# File 'lib/workarea/ext/freedom_patches/string.rb', line 8 def self.optionize_unwanted_chars_regex @optionize_unwanted_chars_regex ||= /[^a-z0-9\-_]+/ end |
Instance Method Details
#optionize(sep = '-') ⇒ Object Also known as: slugify, systemize
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/workarea/ext/freedom_patches/string.rb', line 16 def optionize(sep = '-') result = downcase result.strip! # Turn unwanted chars into the separator result.gsub!(String.optionize_unwanted_chars_regex, sep) # No more than one of the separator in a row. String.optionize_seperator_regexes[sep] ||= /#{Regexp.escape(sep)}{2,}/ result.gsub!(String.optionize_seperator_regexes[sep], sep) result.underscore end |