Class: DeepClassCompare::ArrayMatcher

Inherits:
Matcher show all
Includes:
ContainerComparable
Defined in:
lib/deep_class_compare/array_matcher.rb

Instance Method Summary collapse

Methods inherited from Matcher

build

Constructor Details

#initialize(klass = Array) ⇒ ArrayMatcher

Returns a new instance of ArrayMatcher.



4
5
6
# File 'lib/deep_class_compare/array_matcher.rb', line 4

def initialize(klass = Array)
  super(klass)
end

Instance Method Details

#build_chain(*comparable) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/deep_class_compare/array_matcher.rb', line 18

def build_chain(*comparable)
  @chain = if @chain.nil?
    parse_comparable_to_chain(comparable.first)
  elsif @chain.is_a?(Matcher)
    @chain.of(*comparable)
  end
  raise_pattern_error! if @chain.nil?
end

#match?(array) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/deep_class_compare/array_matcher.rb', line 8

def match?(array)
  super && compare_array_with_chain(array)
end

#of(*comparable) ⇒ Object



12
13
14
15
16
# File 'lib/deep_class_compare/array_matcher.rb', line 12

def of(*comparable)
  dup.tap do |matcher|
    matcher.build_chain(*comparable)
  end
end