Class: WildcardMatchers::WildcardMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/wildcard_matchers/wildcard_matcher.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expectation = nil, position = ".", &block) ⇒ WildcardMatcher

Returns a new instance of WildcardMatcher.



6
7
8
9
# File 'lib/wildcard_matchers/wildcard_matcher.rb', line 6

def initialize(expectation = nil, position = ".", &block)
  @expectation = (block_given? ? block : expectation)
  @position    = position
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



3
4
5
# File 'lib/wildcard_matchers/wildcard_matcher.rb', line 3

def errors
  @errors
end

#expectationObject (readonly)

Returns the value of attribute expectation.



3
4
5
# File 'lib/wildcard_matchers/wildcard_matcher.rb', line 3

def expectation
  @expectation
end

#positionObject

Returns the value of attribute position.



4
5
6
# File 'lib/wildcard_matchers/wildcard_matcher.rb', line 4

def position
  @position
end

Class Method Details

.check_errors(actual, expectation = nil, position = ".", &block) ⇒ Object



25
26
27
28
29
30
# File 'lib/wildcard_matchers/wildcard_matcher.rb', line 25

def self.check_errors(actual, expectation = nil, position = ".", &block)
  expectation = (block_given? ? block : expectation)
  matcher = self.new(expectation, position)
  matcher === actual
  matcher.errors
end

Instance Method Details

#&(matcher) ⇒ Object



11
12
13
# File 'lib/wildcard_matchers/wildcard_matcher.rb', line 11

def &(matcher)
  WildcardMatchers::Helpers::AllOf.new([self, matcher])
end

#===(actual) ⇒ Object



19
20
21
22
23
# File 'lib/wildcard_matchers/wildcard_matcher.rb', line 19

def ===(actual)
  @errors = []
  wildcard_match_with_catch_exception(actual)
  errors.empty?
end

#|(matcher) ⇒ Object



15
16
17
# File 'lib/wildcard_matchers/wildcard_matcher.rb', line 15

def |(matcher)
  WildcardMatchers::Helpers::AnyOf.new([self, matcher])
end