File: double_matches.rb

package info (click to toggle)
ruby-rr 3.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,424 kB
  • sloc: ruby: 11,405; makefile: 7
file content (44 lines) | stat: -rw-r--r-- 1,361 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module RR
  class DoubleMatches
    attr_reader :matching_doubles,
                :exact_terminal_doubles_to_attempt,
                :exact_non_terminal_doubles_to_attempt,
                :wildcard_terminal_doubles_to_attempt,
                :wildcard_non_terminal_doubles_to_attempt

    def initialize(doubles) #:nodoc:
      @doubles = doubles
      @matching_doubles = []
      @exact_terminal_doubles_to_attempt = []
      @exact_non_terminal_doubles_to_attempt = []
      @wildcard_terminal_doubles_to_attempt = []
      @wildcard_non_terminal_doubles_to_attempt = []
    end

    def find_all_matches(args, kwargs)
      kwargs ||= {}
      @doubles.each do |double|
        if double.exact_match?(args, kwargs)
          matching_doubles << double
          if double.attempt?
            if double.terminal?
              exact_terminal_doubles_to_attempt << double
            else
              exact_non_terminal_doubles_to_attempt << double
            end
          end
        elsif double.wildcard_match?(args, kwargs)
          matching_doubles << double
          if double.attempt?
            if double.terminal?
              wildcard_terminal_doubles_to_attempt << double
            else
              wildcard_non_terminal_doubles_to_attempt << double
            end
          end
        end
      end
      self
    end
  end
end