Class: SlimLint::Matcher::Capture
- 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
-
#matcher ⇒ SlimLint::Matcher::Base
Matcher that this capture wraps.
-
#value ⇒ Object
Value that was captured.
Class Method Summary collapse
-
.from_matcher(matcher) ⇒ SlimLint::Matcher::Capture
Creates a capture that wraps that given matcher.
Instance Method Summary collapse
Instance Attribute Details
#matcher ⇒ SlimLint::Matcher::Base
Returns matcher that this capture wraps.
8 9 10 |
# File 'lib/slim_lint/matcher/capture.rb', line 8 def matcher @matcher end |
#value ⇒ Object
Returns value that was captured.
11 12 13 |
# File 'lib/slim_lint/matcher/capture.rb', line 11 def value @value end |
Class Method Details
.from_matcher(matcher) ⇒ SlimLint::Matcher::Capture
Creates a capture that wraps that given matcher.
17 18 19 20 21 |
# File 'lib/slim_lint/matcher/capture.rb', line 17 def self.from_matcher(matcher) new.tap do |cap_matcher| cap_matcher.matcher = matcher end end |
Instance Method Details
#match?(object) ⇒ Boolean
24 25 26 27 28 29 30 |
# File 'lib/slim_lint/matcher/capture.rb', line 24 def match?(object) if result = @matcher.match?(object) @value = object end result end |