Class: SlimLint::Matcher::Capture

Inherits:
Base
  • Object
show all
Defined in:
lib/slim_lint/matcher/capture.rb

Overview

Wraps a matcher, taking on the behavior of the wrapped matcher but storing the value that matched so it can be referred to later.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#matcherSlimLint::Matcher::Base



6
7
8
# File 'lib/slim_lint/matcher/capture.rb', line 6

def matcher
  @matcher
end

#valueObject



9
10
11
# File 'lib/slim_lint/matcher/capture.rb', line 9

def value
  @value
end

Class Method Details

.from_matcher(matcher) ⇒ SlimLint::Matcher::Capture

Creates a capture that wraps that given matcher.



15
16
17
18
19
# File 'lib/slim_lint/matcher/capture.rb', line 15

def self.from_matcher(matcher)
  new.tap do |cap_matcher|
    cap_matcher.matcher = matcher
  end
end

Instance Method Details

#match?(object) ⇒ Boolean

See Also:

  • SlimLint::Matcher::Capture.{SlimLint{SlimLint::Matcher{SlimLint::Matcher::Base{SlimLint::Matcher::Base#match?}


22
23
24
25
26
27
28
# File 'lib/slim_lint/matcher/capture.rb', line 22

def match?(object)
  if result = @matcher.match?(object)
    @value = object
  end

  result
end