Class: Welo::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/welo/core/matcher.rb

Direct Known Subclasses

EpithetMatcher, IdentifyingMatcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, prefix = '') ⇒ Matcher

Initializes a new matcher for the set of params (a hash) a prefix may be given, in which case, only the keys prefixed by the prefix will be selected.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/welo/core/matcher.rb', line 9

def initialize(params, prefix='')
  @prefix = prefix.dup.freeze
  @params = if prefix.empty?
    params.dup.freeze
  else
    h = {}
    keys = params.keys.select do |k|
      k.start_with?(prefix)
    end
    keys.each do |k|
      h[k] = params[k]
    end
    h.freeze
  end
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'lib/welo/core/matcher.rb', line 4

def params
  @params
end

#prefixObject (readonly)

Returns the value of attribute prefix.



4
5
6
# File 'lib/welo/core/matcher.rb', line 4

def prefix
  @prefix
end

Instance Method Details

#missing_params?(*args) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/welo/core/matcher.rb', line 25

def missing_params?(*args)
  missing_params(*args).any?
end

#too_many_params?(*args) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/welo/core/matcher.rb', line 29

def too_many_params?(*args)
  extra_params(*args).any?
end

#wrong_params_set?(*args) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/welo/core/matcher.rb', line 33

def wrong_params_set?(*args)
  missing_params?(*args) or 
  too_many_params?(*args)
end