Module: PinYin::Punctuation
- Defined in:
- lib/ruby-pinyin/punctuation.rb
Class Method Summary collapse
- .[](code) ⇒ Object
- .chinese_regexp ⇒ Object
- .include?(code) ⇒ Boolean
- .load_from(file) ⇒ Object
- .punctuations ⇒ Object
- .regexp ⇒ Object
Class Method Details
.[](code) ⇒ Object
18 19 20 |
# File 'lib/ruby-pinyin/punctuation.rb', line 18 def [](code) punctuations[code] end |
.chinese_regexp ⇒ Object
14 15 16 |
# File 'lib/ruby-pinyin/punctuation.rb', line 14 def chinese_regexp @chinese_regexp ||= /([\u3000-\u303F\uFF00-\uFFEF]+)/ end |
.include?(code) ⇒ 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 |
.punctuations ⇒ Object
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.('../data/Punctuations.dat', __FILE__) load_from src @punctuations end |
.regexp ⇒ Object
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 |