Module: PinYin::Punctuation

Defined in:
lib/ruby-pinyin/punctuation.rb

Class Method Summary collapse

Class Method Details

.[](code) ⇒ Object



18
19
20
# File 'lib/ruby-pinyin/punctuation.rb', line 18

def [](code)
  punctuations[code]
end

.chinese_regexpObject



14
15
16
# File 'lib/ruby-pinyin/punctuation.rb', line 14

def chinese_regexp
  @chinese_regexp ||= /([\u3000-\u303F\uFF00-\uFFEF]+)/
end

.include?(code) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/ruby-pinyin/punctuation.rb', line 22

def include?(code)
  punctuations.has_key?(code)
end

.load_from(file) ⇒ Object



36
37
38
39
40
41
# File 'lib/ruby-pinyin/punctuation.rb', line 36

def load_from(file)
  File.readlines(file).map do |line|
    from, to = line.split(/\s+/)
    @punctuations[from] = to
  end
end

.punctuationsObject



26
27
28
29
30
31
32
33
34
# File 'lib/ruby-pinyin/punctuation.rb', line 26

def punctuations
  return @punctuations if @punctuations

  @punctuations = {}
  src = File.expand_path('../data/Punctuations.dat', __FILE__)
  load_from src 

  @punctuations
end

.regexpObject



6
7
8
9
10
11
12
# File 'lib/ruby-pinyin/punctuation.rb', line 6

def regexp
  return @regexp if @regexp

  escaped_punctuations = punctuations.values.map {|v| "\\#{[v].pack('H*')}"}.join
  @regexp = Regexp.new "([#{escaped_punctuations}]+)$"
  @regexp
end