Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/immosquare-extensions/string.rb
Overview
============================================================## This extension adds utility methods to the String class. ============================================================##
Instance Method Summary collapse
-
#titleize_name ⇒ Object
============================================================## Titleize a proper name or a label — a person, an agency, a building, an enumeration value.
-
#titleize_place ⇒ Object
============================================================## Titleize a PLACE NAME under French typographic rules: the letter after an apostrophe carries the capital, and particles stay lowercase unless they open the name.
-
#to_boolean(default_value = nil) ⇒ Object
============================================================## Convert the string 'true' to true and 'false' to false.
Instance Method Details
#titleize_name ⇒ Object
============================================================##
Titleize a proper name or a label — a person, an agency, a
building, an enumeration value. Same apostrophe and accent
handling as titleize_place, but every word is capitalized.
Examples: "o'brien".titleize_name => O'Brien "MAISON DE VILLE".titleize_name => Maison De Ville ============================================================##
73 74 75 |
# File 'lib/immosquare-extensions/string.rb', line 73 def titleize_name titleize_words(:lower_particles => false) end |
#titleize_place ⇒ Object
============================================================##
Titleize a PLACE NAME under French typographic rules: the
letter after an apostrophe carries the capital, and particles
stay lowercase unless they open the name. Hyphenated toponyms
are the case standard titleize gets wrong.
Use titleize_name for anything that is not a place — there,
no particle is lowered.
Examples: "SANT-ANDREA-D'ORCINO".titleize_place => Sant-Andrea-d'Orcino "saint-jean-sur-richelieu".titleize_place => Saint-Jean-sur-Richelieu "st john's".titleize_place => St John's "SANT-ANDREA-D'ORCINO".titleize => Sant Andrea D'orcino ============================================================##
60 61 62 |
# File 'lib/immosquare-extensions/string.rb', line 60 def titleize_place titleize_words(:lower_particles => true) end |
#to_boolean(default_value = nil) ⇒ Object
============================================================## Convert the string 'true' to true and 'false' to false. Any other value will return nil.
Examples: "true".to_boolean => true "false".to_boolean => false "random".to_boolean => nil "random".to_boolean(true) => true ============================================================##
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/immosquare-extensions/string.rb', line 34 def to_boolean(default_value = nil) case downcase when "true" true when "false" false else default_value end end |