Module: Leftovers::MatcherBuilders::Or

Defined in:
lib/leftovers/matcher_builders/or.rb

Class Method Summary collapse

Class Method Details

.build(matchers) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/leftovers/matcher_builders/or.rb', line 17

def build(matchers)
  matchers = compact(matchers)
  case matchers.length
    # :nocov:
  when 0 then nil
    # :nocov:
  when 1 then matchers.first
  when 2 then Matchers::Or.new(matchers.first, matchers[1])
  else Matchers::Any.new(matchers.dup)
  end
end

.each_or_self(value, &block) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/leftovers/matcher_builders/or.rb', line 9

def each_or_self(value, &block)
  case value
  when nil then nil
  when ::Array then build(value.map(&block))
  else build([yield(value)])
  end
end