Class: TwitterCldr::Shared::Caser
- Inherits:
-
Object
- Object
- TwitterCldr::Shared::Caser
- Defined in:
- lib/twitter_cldr/shared/caser.rb
Constant Summary collapse
- REGEX =
/./
Class Method Summary collapse
- .downcase(string) ⇒ Object
-
.titlecase(string) ⇒ Object
toTitlecase(X): Find the word boundaries in X according to Unicode Standard Annex #29, “Unicode Text Segmentation.” For each word boundary, find the first cased character F following the word boundary.
- .upcase(string) ⇒ Object
Class Method Details
.downcase(string) ⇒ Object
16 17 18 |
# File 'lib/twitter_cldr/shared/caser.rb', line 16 def downcase(string) string.gsub(REGEX, lowercasing_hash) end |
.titlecase(string) ⇒ Object
toTitlecase(X): Find the word boundaries in X according to Unicode Standard Annex #29, “Unicode Text Segmentation.” For each word boundary, find the first cased character F following the word boundary. If F exists, map F to Titlecase_Mapping(F); then map all characters C between F and the following word boundary to Lowercase_Mapping©.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/twitter_cldr/shared/caser.rb', line 26 def titlecase(string) string.dup.tap do |result| word_iterator.each_word(result) do |_, *boundary_pair| if cased_pos = first_cased(string, *boundary_pair) result[cased_pos] = titlecasing_hash[result[cased_pos]] (cased_pos + 1).upto(boundary_pair.last - 1) do |pos| result[pos] = lowercasing_hash[result[pos]] end end end end end |
.upcase(string) ⇒ Object
12 13 14 |
# File 'lib/twitter_cldr/shared/caser.rb', line 12 def upcase(string) string.gsub(REGEX, uppercasing_hash) end |