Module: PinYin::Punctuation

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

Class Method Summary collapse

Class Method Details

.[](code) ⇒ Object



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

def [](code)
  punctuations[code]
end

.include?(code) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.load_from(file) ⇒ Object



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

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

.punctuationsObject



22
23
24
25
26
27
28
29
30
# File 'lib/ruby-pinyin/punctuation.rb', line 22

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