module PinYin::Punctuation
Public Class Methods
[](code)
click to toggle source
# File lib/ruby_pinyin/punctuation.rb, line 18 def [](code) punctuations[code] end
chinese_regexp()
click to toggle source
# File lib/ruby_pinyin/punctuation.rb, line 14 def chinese_regexp @chinese_regexp ||= /([\u3000-\u303F\uFF00-\uFFEF]+)/ end
include?(code)
click to toggle source
# File lib/ruby_pinyin/punctuation.rb, line 22 def include?(code) punctuations.has_key?(code) end
load_from(file)
click to toggle source
# 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
punctuations()
click to toggle source
# 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
regexp()
click to toggle source
# 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