Class: Arugula
- Inherits:
-
Object
- Object
- Arugula
- Defined in:
- lib/arugula.rb,
lib/arugula/parts.rb,
lib/arugula/parser.rb,
lib/arugula/version.rb
Defined Under Namespace
Modules: MatchAny, Wrapping Classes: AndPart, CharacterClassPart, DotPart, EOLPart, LiteralPart, MatchPart, MetacharacterPart, OrPart, Parser, Part, PlusPart, RangePart, SOLPart, StarPart
Constant Summary collapse
- VERSION =
'0.2.1'.freeze
Instance Method Summary collapse
-
#initialize(pattern) ⇒ Arugula
constructor
A new instance of Arugula.
- #match?(str, index = 0) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(pattern) ⇒ Arugula
Returns a new instance of Arugula.
7 8 9 |
# File 'lib/arugula.rb', line 7 def initialize(pattern) @root = Parser.new(pattern).parse! end |
Instance Method Details
#match?(str, index = 0) ⇒ Boolean
11 12 13 14 15 16 17 18 |
# File 'lib/arugula.rb', line 11 def match?(str, index = 0) loop do match, = @root.match(str, index) return index if match index += 1 return if index > str.size end end |
#to_s ⇒ Object
20 21 22 |
# File 'lib/arugula.rb', line 20 def to_s "/#{@root}/" end |