Class: RsegEngine::Number

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

Constant Summary collapse

@@number_symbols =
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 
'', '', '', '', '', '', '', '', '', '', 
'', '', '', '', '', '', '', '', '', '',
'', '', '', '%', '¥', '', '$', '.', '', '', '']
@@subunit_symbols =
['', '', '', '', '', '', '', '', '', '', 
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '亿', '', '']
@@unit_symbols =
['', '', '', '', '', '', '', '', '', '', 
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', 
'', '', '', '', '', '', '', '', '', '亿', 
'', '', '', '', '', '', '', '', '', '',
'', '', '', '']

Instance Method Summary collapse

Methods inherited from Engine

#run, #running?, #stop

Constructor Details

#initializeNumber

Returns a new instance of Number.



19
20
21
22
23
24
25
# File 'lib/engines/number.rb', line 19

def initialize
  @word = ''
  @number = ''
  @unit = false
  @subunit = false
  super
end

Instance Method Details

#process(char) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/engines/number.rb', line 27

def process(char)
  match = false
  word = nil

  if (!@subunit || @unit) && @@number_symbols.include?(char)
    @number << char
    match = true
    @unit = false
    @subunit = false
  elsif (@number != '' || @unit) && @@subunit_symbols.include?(char)
    @number << char
    match = true
    @subunit = true
  end

  if (@number != '' || @subunit) && @@unit_symbols.include?(char)
    @word << @number
    @word << char if !match
    @number = ''
    @unit = true
    match = true
  end

  if !match
    word = (@word != '') ? @word : @number
    @word = ''
    @number = ''
    match = false
    @unit = false
    @subunit = false
  end

  [match, word]
end