Class: Mat

Inherits:
Combinator show all
Defined in:
lib/hivemind/combinators.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Combinator

#&, #|

Constructor Details

#initialize(regex) ⇒ Mat



32
33
34
# File 'lib/hivemind/combinators.rb', line 32

def initialize(regex)
  @regex = /\A#{regex}/
end

Instance Attribute Details

#regexObject (readonly)

Returns the value of attribute regex.



30
31
32
# File 'lib/hivemind/combinators.rb', line 30

def regex
  @regex
end

Instance Method Details

#parse(input, refs) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/hivemind/combinators.rb', line 36

def parse(input, refs)
  match = @regex.match(input)
  if match
    [true, input[0..match.to_s.size - 1], input[match.to_s.size.. -1]]
  else
    [false, '', input]
  end
end