Module: ChineseInitial::Core
- Defined in:
- lib/chinese_initial/core.rb
Class Method Summary collapse
Class Method Details
.chinese?(chines_code_point) ⇒ Boolean
21 22 23 |
# File 'lib/chinese_initial/core.rb', line 21 def self.chinese?(chines_code_point) (CHINESE_CODE_START..CHINESE_CODE_END) === chines_code_point end |
.get_initial(word) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/chinese_initial/core.rb', line 5 def self.get_initial(word) return if word.nil? || word.to_s.strip.empty? chinese = word[0] codepoint = chinese.codepoints[0] chinese_initial = (chinese?(codepoint) ? CODE_TABLE[codepoint - CHINESE_CODE_START] : chinese) return chinese_initial.upcase end |
.to_pinyin(word) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/chinese_initial/core.rb', line 13 def self.(word) = "" word.each_codepoint do |codepoint| << (chinese?(codepoint) ? CODE_TABLE[codepoint - CHINESE_CODE_START] : chinese) end return .downcase end |