Class: MatchInOrder

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

Instance Method Summary collapse

Constructor Details

#initialize(regexps) ⇒ MatchInOrder

Returns a new instance of MatchInOrder.



2
3
4
# File 'lib/match_in_order.rb', line 2

def initialize(regexps)
  @regexps = regexps
end

Instance Method Details

#failure_messageObject



20
21
22
# File 'lib/match_in_order.rb', line 20

def failure_message
  "expected #{@failure_string.inspect} to match #{@failure_regex.inspect}\nwithin string: #{@target.inspect}"
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/match_in_order.rb', line 6

def matches?(target)
  @target = target
  @regexps.inject(target) do |str, regexp|
    m = str.match(regexp)
    if m.nil?
      @failure_string = str
      @failure_regex = regexp
      return false
    end
    m.post_match
  end
  true
end

#negative_failure_messageObject



24
25
26
# File 'lib/match_in_order.rb', line 24

def negative_failure_message
  "expected #{@target.inspect} to not match in order against: #{@regexps.inspect}"
end