Class: Farseer::Chars

Inherits:
Object
  • Object
show all
Includes:
MapFactory
Defined in:
lib/farseer/chars.rb

Constant Summary collapse

DIGITS =
new(('0'..'9').to_a)
BASIC_MATH_OP =
new(['+', '-', '*', '/'])

Instance Method Summary collapse

Methods included from MapFactory

#map

Constructor Details

#initialize(*chars) ⇒ Chars

Returns a new instance of Chars.



7
8
9
10
# File 'lib/farseer/chars.rb', line 7

def initialize(*chars)
  @chars = chars.flatten
  freeze
end

Instance Method Details

#parse(input) ⇒ Object



15
16
17
18
19
20
# File 'lib/farseer/chars.rb', line 15

def parse(input)
  case input[0]
  when *@chars then Maybe.return(Result.new(input[0], input[1..]))
  else Maybe.none
  end
end