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


15
16
17
18
# File 'lib/fear/extractor/extractor_matcher.rb', line 15

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

Instance Attribute Details

#arguments_matcherArrayMatcher | EmptyListMatcher


15
16
17
18
# File 'lib/fear/extractor/extractor_matcher.rb', line 15

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

#nameTypes::Strict::String


15
16
17
18
# File 'lib/fear/extractor/extractor_matcher.rb', line 15

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.


29
30
31
32
33
# File 'lib/fear/extractor/extractor_matcher.rb', line 29

def call_or_else(arg)
  extractor.(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.


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

def defined_at?(other)
  extractor
    .(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.


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

def failure_reason(other)
  extractor.(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