Module: NobleNames::CoreExt::String
- Defined in:
- lib/noble_names/core_ext/string.rb
Overview
This Module gives String the capability to titleize itself.
Instance Method Summary collapse
-
#to_title ⇒ String
Capitalizes each Word in a name except for those which are nobility particles.
-
#to_title! ⇒ Object
Does the same as #to_title but replaces the old string.
Instance Method Details
#to_title ⇒ String
Capitalizes each Word in a name except for those which are nobility particles
14 15 16 |
# File 'lib/noble_names/core_ext/string.rb', line 14 def to_title dup.to_title! end |
#to_title! ⇒ Object
Does the same as #to_title but replaces the old string.
23 24 25 26 27 28 29 30 31 |
# File 'lib/noble_names/core_ext/string.rb', line 23 def to_title! words = split(/\s+/) if words.any? { |w| NobleNames.business_particle? w } NobleNames.correct_business_particles words else words.map! { |w| NobleNames.noble_capitalize(w) } end replace(words * ' ') end |