Class: Mat
- Inherits:
-
Combinator
- Object
- Combinator
- Mat
- Defined in:
- lib/hivemind/combinators.rb
Instance Attribute Summary collapse
-
#regex ⇒ Object
readonly
Returns the value of attribute regex.
Instance Method Summary collapse
-
#initialize(regex) ⇒ Mat
constructor
A new instance of Mat.
- #parse(input, refs) ⇒ Object
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
#regex ⇒ Object (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 |