Class: Text::Gen::Function::Titleizer
- Inherits:
-
Object
- Object
- Text::Gen::Function::Titleizer
- Defined in:
- lib/text/gen/function/titleizer.rb
Constant Summary collapse
- SKIP_WORDS =
Set.new(%w[a an and as at but by for if in of on or the to v via vs])
Class Method Summary collapse
Class Method Details
.titleize(str) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/text/gen/function/titleizer.rb', line 10 def titleize(str) arr = str.split(/\s+/) idx = 0 len = arr.length while idx < len arr[idx] = arr[idx].capitalize if idx.zero? || !SKIP_WORDS.include?(arr[idx]) idx += 1 end arr.join(" ") end |