Module: Relaton::Render::Template::SelectiveCapitalize
- Defined in:
- lib/relaton/render/selective_capitalize.rb
Instance Method Summary collapse
Instance Method Details
#selective_capitalize(input, exceptions) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/relaton/render/selective_capitalize.rb', line 5 def selective_capitalize(input, exceptions) return nil if input.nil? # Convert exceptions to an array if it's not already exceptions_array = exceptions.is_a?(Array) ? exceptions : [exceptions] # Split the input into words words = input.split(/\s+/) # Capitalize each word unless it's in the exceptions list words.map do |word| if exceptions_array.include?(word.downcase) word else word.capitalize end end.join(' ') end |