Module: ZhongwenTools::Caps
- Defined in:
- lib/zhongwen_tools/caps.rb
Overview
Public: Module for pinyin/fullwidth capitalization
Constant Summary collapse
- CAPS =
{ 'Ā' => 'ā', 'Á' => 'á', 'Ǎ' => 'ǎ', 'À' => 'à', 'Ē' => 'ē', 'É' => 'é', 'Ě' => 'ě', 'È' => 'è', 'Ī' => 'ī', 'Í' => 'í', 'Ǐ' => 'ǐ', 'Ì' => 'ì', 'Ō' => 'ō', 'Ó' => 'ó', 'Ǒ' => 'ǒ', 'Ò' => 'ò', 'Ǖ' => 'ǖ', # using combining diatrical marks 'Ǘ' => 'ǘ', # using combining diatrical marks 'Ǚ' => 'ǚ', # using combining diatrical marks 'Ǜ' => 'ǜ', # using combining diatrical marks 'Ū' => 'ū', 'Ú' => 'ú', 'Ǔ' => 'ǔ', 'Ù' => 'ù', 'A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e', 'F' => 'f', 'G' => 'g', 'H' => 'h', 'I' => 'i', 'J' => 'j', 'K' => 'k', 'L' => 'l', 'M' => 'm', 'N' => 'n', 'O' => 'o', 'P' => 'p', 'Q' => 'q', 'R' => 'r', 'S' => 's', 'T' => 't', 'U' => 'u', 'V' => 'v', 'W' => 'w', 'X' => 'x', 'Y' => 'y', 'Z' => 'z' }
Class Method Summary collapse
Class Method Details
.capitalize(str) ⇒ Object
15 16 17 18 |
# File 'lib/zhongwen_tools/caps.rb', line 15 def self.capitalize(str) first_letter = str[ZhongwenTools::Regex.capitalize][0] str.sub(first_letter, ZhongwenTools::Caps.upcase(first_letter)) end |
.downcase(str) ⇒ Object
5 6 7 |
# File 'lib/zhongwen_tools/caps.rb', line 5 def self.downcase(str) str.gsub(ZhongwenTools::Regex.capital_letters, ZhongwenTools::Caps::CAPS).downcase end |
.upcase(str) ⇒ Object
9 10 11 12 13 |
# File 'lib/zhongwen_tools/caps.rb', line 9 def self.upcase(str) str.gsub(ZhongwenTools::Regex.lowercase_letters) do ZhongwenTools::Caps::CAPS.find { |_, v| v == Regexp.last_match[0] }[0] end.upcase end |