Module: ZhongwenTools::Caps

Defined in:
lib/zhongwen_tools/caps.rb

Constant Summary collapse

CAPS =
{
  'Ā' => 'ā',
  'Á' => 'á',
  'Ǎ' => 'ǎ',
  'À' => 'à',
  'Ē' => 'ē',
  'É' => 'é',
  'Ě' => 'ě',
  'È' => 'è',
  'Ī' => 'ī',
  'Í' => 'í',
  'Ǐ' => 'ǐ',
  'Ì' => 'ì',
  'Ō' => 'ō',
  'Ó' => 'ó',
  'Ǒ' => 'ǒ',
  'Ò' => 'ò',
  'Ǖ' => 'ǖ', # using combining diatrical marks
  'Ǘ' => 'ǘ', # using combining diatrical marks
  'Ǚ' => 'ǚ', # using combining diatrical marks
  'Ǜ' => 'ǜ', # using combining diatrical marks
  'Ū' => 'ū',
  'Ú' => 'ú',
  'Ǔ' => 'ǔ',
  'Ù' => 'ù',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => '',
  '' => ''
}

Class Method Summary collapse

Class Method Details

.capitalize(str) ⇒ Object



17
18
19
# File 'lib/zhongwen_tools/caps.rb', line 17

def self.capitalize(str)
  str.sub(str[0], ZhongwenTools::Caps.upcase(str[0]))
end

.downcase(str) ⇒ Object



6
7
8
9
# File 'lib/zhongwen_tools/caps.rb', line 6

def self.downcase(str)
  regex = /(#{ZhongwenTools::Caps::CAPS.keys.join('|')})/
  str.gsub(regex, ZhongwenTools::Caps::CAPS).downcase
end

.upcase(str) ⇒ Object



11
12
13
14
15
# File 'lib/zhongwen_tools/caps.rb', line 11

def self.upcase(str)
  str.gsub(/(#{ZhongwenTools::Caps::CAPS.values.join('|')})/){
    ZhongwenTools::Caps::CAPS.find{ |k, v| v == $1 }[0]
  }.upcase
end