Class: Pinyin
- Inherits:
-
Object
- Object
- Pinyin
- Defined in:
- lib/pinyin.rb
Instance Method Summary collapse
-
#initialize ⇒ Pinyin
constructor
Initialize using Pinyin.new py = Pinyin.new.
-
#to_permlink(str) ⇒ Object
Generating permlink using ‘-’ split Show the permlink: Interesting-Ruby-Tidbits-That-Dont-Need-Separate-Posts-17 You can also pass a split symbol to_permlink(str, ‘~’).
-
#to_pinyin(str, separator = '', tone = false) ⇒ Object
通用情况 tone为取第几声的标识。eg.
-
#to_pinyin_abbr(str) ⇒ Object
Generating shorter permlink with first letter of each charater Like: zgyh stands for “中国银行”.
-
#to_pinyin_abbr_else(str) ⇒ Object
第一个字取全部,后面首字母.名称缩写。eg.
Constructor Details
#initialize ⇒ Pinyin
Initialize using Pinyin.new py = Pinyin.new
7 8 9 10 11 12 13 14 |
# File 'lib/pinyin.rb', line 7 def initialize ma = File.join(File.dirname(File.(__FILE__)),'../dict/Mandarin.dat') @codes = {} File.readlines(ma).each do |line| nv = line.split(/\s/) @codes[nv[0]] = nv[1] end end |
Instance Method Details
#to_permlink(str) ⇒ Object
Generating permlink using ‘-’ split Show the permlink: Interesting-Ruby-Tidbits-That-Dont-Need-Separate-Posts-17 You can also pass a split symbol to_permlink(str, ‘~’)
19 20 21 |
# File 'lib/pinyin.rb', line 19 def to_permlink(str) (str,'-') end |
#to_pinyin(str, separator = '', tone = false) ⇒ Object
通用情况 tone为取第几声的标识。eg. ni3hao3zhong1guo2
35 36 37 |
# File 'lib/pinyin.rb', line 35 def (str,separator='',tone=false) (str,separator,false,false,tone) end |
#to_pinyin_abbr(str) ⇒ Object
Generating shorter permlink with first letter of each charater Like: zgyh stands for “中国银行”
25 26 27 |
# File 'lib/pinyin.rb', line 25 def (str) (str,'',false,true) end |
#to_pinyin_abbr_else(str) ⇒ Object
第一个字取全部,后面首字母.名称缩写。eg. liudh 刘德华
30 31 32 |
# File 'lib/pinyin.rb', line 30 def (str) (str,'',true,nil) end |