Module: PinYin

Defined in:
lib/ruby-pinyin.rb,
lib/ruby-pinyin/util.rb,
lib/ruby-pinyin/value.rb,
lib/ruby-pinyin/backend.rb,
lib/ruby-pinyin/version.rb,
lib/ruby-pinyin/punctuation.rb,
lib/ruby-pinyin/backend/mmseg.rb,
lib/ruby-pinyin/backend/simple.rb

Defined Under Namespace

Modules: Backend, Punctuation, Util Classes: Value

Constant Summary collapse

VERSION =
'0.5.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.backendObject

Returns the value of attribute backend.



9
10
11
# File 'lib/ruby-pinyin.rb', line 9

def backend
  @backend
end

Class Method Details

.abbr(str, except_lead = false, except_english = true) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/ruby-pinyin.rb', line 20

def abbr(str, except_lead=false, except_english=true)
  result = ""
  of_string(str).each_with_index do |word, i|
    w = (except_lead && i == 0) || (except_english && word.english?) ? word : word[0]
    result << w
  end
  result
end

.override_files=(files) ⇒ Object



33
34
35
36
# File 'lib/ruby-pinyin.rb', line 33

def override_files=(files)
  klass = backend ? backend.class : PinYin::Backend::MMSeg
  self.backend = klass.new files
end


16
17
18
# File 'lib/ruby-pinyin.rb', line 16

def permlink(str, sep='-')
  of_string(str).join(sep)
end

.romanize(str, tone = nil, include_punctuations = false) ⇒ Object Also known as: of_string



11
12
13
# File 'lib/ruby-pinyin.rb', line 11

def romanize(str, tone=nil, include_punctuations=false)
  backend.romanize(str, tone, include_punctuations)
end

.sentence(str, tone = nil) ⇒ Object



29
30
31
# File 'lib/ruby-pinyin.rb', line 29

def sentence(str, tone=nil)
  of_string(str, tone, true).join(' ')
end