Class: RsegEngine::Dict

Inherits:
Engine
  • Object
show all
Defined in:
lib/engines/dict.rb

Constant Summary collapse

@@root =
nil
@@dict_path =
File.join(File.dirname(__FILE__), '../../dict/dict.hash')

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Engine

#run, #running?, #stop

Constructor Details

#initializeDict

Returns a new instance of Dict.



16
17
18
19
20
21
# File 'lib/engines/dict.rb', line 16

def initialize
  @@root ||= load_dict(@@dict_path)
  @word = ''
  @node = @@root
  super
end

Class Method Details

.dict_pathObject



11
12
13
# File 'lib/engines/dict.rb', line 11

def dict_path
  @@dict_path
end

.dict_path=(path) ⇒ Object



7
8
9
# File 'lib/engines/dict.rb', line 7

def dict_path=(path)
  @@dict_path = path
end

Instance Method Details

#process(char) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/engines/dict.rb', line 23

def process(char)
  match = false
  word = nil

  if @node[char]
    @word << char
    @node = @node[char]
    match = true
  else
    if @node[:end] || @word.chars.to_a.length == 1
      word = @word
    else
      word = @word.chars.to_a
    end
  
    @node = @@root
    @word = ''
    match = false
  end

  [match, word]
end