diff options
author | Xavier Noria <fxn@hashref.com> | 2015-10-07 23:43:58 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2015-10-07 23:44:04 +0200 |
commit | eaa0cb7924d5ffd0de04492a7198e0d79088aaae (patch) | |
tree | aed296a37555b790ffc61dd4380017594cf3f76c | |
parent | fef1064052aeda3701913d3171f17fd4fc84d3f0 (diff) | |
download | rails-eaa0cb7924d5ffd0de04492a7198e0d79088aaae.tar.gz rails-eaa0cb7924d5ffd0de04492a7198e0d79088aaae.tar.bz2 rails-eaa0cb7924d5ffd0de04492a7198e0d79088aaae.zip |
code gardening in transliterate.rb
Saw this while doing a review of a patch:
* Normalize case and punctuation across comments.
* ascii -> ASCII
* Since I was on it, some blank lines that visually
add some clarity IMO.
-rw-r--r-- | activesupport/lib/active_support/inflector/transliterate.rb | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/inflector/transliterate.rb b/activesupport/lib/active_support/inflector/transliterate.rb index 7472d4386a..103207fb63 100644 --- a/activesupport/lib/active_support/inflector/transliterate.rb +++ b/activesupport/lib/active_support/inflector/transliterate.rb @@ -69,10 +69,12 @@ module ActiveSupport # parameterize("Donald E. Knuth") # => "donald-e-knuth" # parameterize("^trés|Jolie-- ") # => "tres-jolie" def parameterize(string, sep = '-') - # replace accented chars with their ascii equivalents + # Replace accented chars with their ASCII equivalents. parameterized_string = transliterate(string) - # Turn unwanted chars into the separator + + # Turn unwanted chars into the separator. parameterized_string.gsub!(/[^a-z0-9\-_]+/i, sep) + unless sep.nil? || sep.empty? if sep == "-".freeze re_duplicate_separator = /-{2,}/ @@ -87,6 +89,7 @@ module ActiveSupport # Remove leading/trailing separator. parameterized_string.gsub!(re_leading_trailing_separator, ''.freeze) end + parameterized_string.downcase! parameterized_string end |