Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string/smart_titleize.rb
Instance Method Summary collapse
Instance Method Details
#smart_titleize ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/string/smart_titleize.rb', line 2 def smart_titleize new_str = [] exclusions = %w{with to or and for but nor} self.split(' ').each.with_index do |word, i| new_word = word unless word.scan(/[A-Z]/).size > 1 unless (exclusions.include?(word)) && i != 0 && i != (self.size - 1) new_word = word.capitalize end end new_str << new_word end new_str.join(' ') end |