Class: RsegEngine::Name

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

Constant Summary collapse

@@last_names =
%W(                            
                              
                              
        羿                   
                                                 
                           宿     
                                           
                                    
                寿  
             广    
                     
                     
           
         怀        ) 
@@first_names =
%W(                       
                       
                       
                     鸿  
            ) 

Instance Method Summary collapse

Methods inherited from Engine

#run, #running?, #stop

Constructor Details

#initializeName

Returns a new instance of Name.



24
25
26
27
28
# File 'lib/engines/name.rb', line 24

def initialize
  @word = ''
  @last = false
  super
end

Instance Method Details

#process(char) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/engines/name.rb', line 30

def process(char)
  match = false
  word = nil

  if !@last && @@last_names.include?(char)
      @word << char
      match = true
      @last = true
  elsif @last && @word.chars.to_a.length < 3 && @@first_names.include?(char)
      @word << char
      match = true
      @unit = true
  else
    word = @word
    @word = ''
    @last = false
    match = false
  end

  [match, word]
end