Module: Qo

Defined in:
lib/qo.rb,
lib/qo/matcher.rb,
lib/qo/version.rb,
lib/qo/guard_block_matcher.rb

Defined Under Namespace

Classes: GuardBlockMatcher, Matcher

Constant Summary collapse

WILDCARD_MATCH =
:*
VERSION =
'0.1.5'

Class Method Summary collapse

Class Method Details

.[](*array_matchers, **keyword_matchers) ⇒ Object



27
28
29
# File 'lib/qo.rb', line 27

def [](*array_matchers, **keyword_matchers)
  Qo::Matcher.new('and', *array_matchers, **keyword_matchers)
end

.and(*array_matchers, **keyword_matchers) ⇒ Object



23
24
25
# File 'lib/qo.rb', line 23

def and(*array_matchers, **keyword_matchers)
  Qo::Matcher.new('and', *array_matchers, **keyword_matchers)
end

.m(*array_matchers, **keyword_matchers, &fn) ⇒ Object



9
10
11
# File 'lib/qo.rb', line 9

def m(*array_matchers, **keyword_matchers, &fn)
  Qo::GuardBlockMatcher.new(*array_matchers, **keyword_matchers, &fn)
end

.match(data, *qo_matchers) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/qo.rb', line 13

def match(data, *qo_matchers)
  all_are_guards = qo_matchers.all? { |q| q.is_a?(Qo::GuardBlockMatcher)}
  raise 'Must patch Qo GuardBlockMatchers!' unless all_are_guards

  qo_matchers.reduce(nil) { |_, matcher|
    did_match, match_result = matcher.call(data)
    break match_result if did_match
  }
end

.not(*array_matchers, **keyword_matchers) ⇒ Object



35
36
37
# File 'lib/qo.rb', line 35

def not(*array_matchers, **keyword_matchers)
  Qo::Matcher.new('not', *array_matchers, **keyword_matchers)
end

.or(*array_matchers, **keyword_matchers) ⇒ Object



31
32
33
# File 'lib/qo.rb', line 31

def or(*array_matchers, **keyword_matchers)
  Qo::Matcher.new('or', *array_matchers, **keyword_matchers)
end