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

Returns matcher that this capture wraps.

Returns:



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

def matcher
  @matcher
end

#valueObject

Returns value that was captured.

Returns:

  • (Object)

    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.

Parameters:

Returns:



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

Returns:

  • (Boolean)

See Also:

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


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