Class: Fear::Extractor::ExtractorMatcher Private

Inherits:
Matcher
  • Object
show all
Defined in:
lib/fear/extractor/extractor_matcher.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Match and extract pattern using registered extractor objects E.g. Some(a : Integer)

See Also:

Constant Summary

Constants inherited from Matcher

Matcher::EMPTY_ARRAY, Matcher::EMPTY_HASH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Matcher

#and, #call

Constructor Details

#initializeExtractorMatcher

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ExtractorMatcher.



13
14
15
16
# File 'lib/fear/extractor/extractor_matcher.rb', line 13

def initialize(*)
  super
  @extractor = Extractor.find_extractor(name)
end

Instance Attribute Details

#arguments_matcherArrayMatcher | EmptyListMatcher



13
14
15
16
# File 'lib/fear/extractor/extractor_matcher.rb', line 13

def initialize(*)
  super
  @extractor = Extractor.find_extractor(name)
end

#nameTypes::Strict::String

Returns:

  • (Types::Strict::String)


13
14
15
16
# File 'lib/fear/extractor/extractor_matcher.rb', line 13

def initialize(*)
  super
  @extractor = Extractor.find_extractor(name)
end

Instance Method Details

#call_or_else(arg) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
30
31
# File 'lib/fear/extractor/extractor_matcher.rb', line 27

def call_or_else(arg)
  extractor.call(arg)
    .map { |v| arguments_matcher.call_or_else(v) { yield arg } }
    .get_or_else { yield arg }
end

#defined_at?(other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/fear/extractor/extractor_matcher.rb', line 20

def defined_at?(other)
  extractor
    .call(other)
    .map { |v| arguments_matcher.defined_at?(v) }
    .get_or_else(false)
end

#failure_reason(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



33
34
35
36
37
38
39
# File 'lib/fear/extractor/extractor_matcher.rb', line 33

def failure_reason(other)
  extractor.call(other).match do |m|
    m.some(->(v) { arguments_matcher.defined_at?(v) }) { Fear.none }
    m.some { |v| arguments_matcher.failure_reason(v) }
    m.none { super }
  end
end