Class: Kommando::Matchers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/kommando/matchers/base.rb

Direct Known Subclasses

Every, Once

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(regexp, block) ⇒ Base

Returns a new instance of Base.



4
5
6
7
8
9
# File 'lib/kommando/matchers/base.rb', line 4

def initialize(regexp, block)
  @regexp = regexp
  @block = block

  @nested_matchers = []
end

Instance Attribute Details

#nested_matchersObject (readonly)

Returns the value of attribute nested_matchers.



2
3
4
# File 'lib/kommando/matchers/base.rb', line 2

def nested_matchers
  @nested_matchers
end

Instance Method Details

#call(match_data = nil) ⇒ Object



15
16
17
18
# File 'lib/kommando/matchers/base.rb', line 15

def call(match_data=nil)
  return unless @block
  @block.call match_data
end

#every(regexp, &block) ⇒ Object



26
27
28
29
30
# File 'lib/kommando/matchers/base.rb', line 26

def every(regexp, &block)
  m = Kommando::Matchers::Every.new regexp, block
  @nested_matchers << m
  m
end

#match(string) ⇒ Object



11
12
13
# File 'lib/kommando/matchers/base.rb', line 11

def match(string)
  raise "#match not implemented"
end

#once(regexp, &block) ⇒ Object



20
21
22
23
24
# File 'lib/kommando/matchers/base.rb', line 20

def once(regexp, &block)
  m = Kommando::Matchers::Once.new regexp, block
  @nested_matchers << m
  m
end