Class: AgideoPinyin

Inherits:
Object
  • Object
show all
Defined in:
lib/agideo_pinyin/pinyin.rb

Constant Summary collapse

@@dist =
YAML.load_file(File.dirname(__FILE__) + "/../../dist.yml")

Class Method Summary collapse

Class Method Details

.abbr(value) ⇒ Object



10
11
12
# File 'lib/agideo_pinyin/pinyin.rb', line 10

def self.abbr(value)
  convert_py(value).map{|v| v[0,1]}.join
end

.abbr_else(value) ⇒ Object



14
15
16
17
# File 'lib/agideo_pinyin/pinyin.rb', line 14

def self.abbr_else(value)
  words = self.split(value)
  self.full(words.shift) + self.abbr(words.join)
end

.convert_py(value) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/agideo_pinyin/pinyin.rb', line 19

def self.convert_py(value)
  result = []
  split(value).each do |v|
    result << find_etymon(v)
  end
  result
end

.find_etymon(word) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/agideo_pinyin/pinyin.rb', line 31

def self.find_etymon(word)
  @@dist.each  do |k, v|
    if v.match(word)
      return k
    end
  end
  word
end

.full(value) ⇒ Object



6
7
8
# File 'lib/agideo_pinyin/pinyin.rb', line 6

def self.full(value)
  convert_py(value).join
end

.split(value) ⇒ Object



27
28
29
# File 'lib/agideo_pinyin/pinyin.rb', line 27

def self.split(value)
  value.clone.split(//)
end