Class: Arugula

Inherits:
Object
  • Object
show all
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

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

Returns:

  • (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_sObject



20
21
22
# File 'lib/arugula.rb', line 20

def to_s
  "/#{@root}/"
end