Class: MatchInOrder
- Inherits:
-
Object
- Object
- MatchInOrder
- Defined in:
- lib/match_in_order.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(regexps) ⇒ MatchInOrder
constructor
A new instance of MatchInOrder.
- #matches?(target) ⇒ Boolean
- #negative_failure_message ⇒ Object
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_message ⇒ Object
20 21 22 |
# File 'lib/match_in_order.rb', line 20 def "expected #{@failure_string.inspect} to match #{@failure_regex.inspect}\nwithin string: #{@target.inspect}" end |
#matches?(target) ⇒ 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_message ⇒ Object
24 25 26 |
# File 'lib/match_in_order.rb', line 24 def "expected #{@target.inspect} to not match in order against: #{@regexps.inspect}" end |