Class: Welo::Matcher
- Inherits:
-
Object
- Object
- Welo::Matcher
- Defined in:
- lib/welo/core/matcher.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
-
#initialize(params, prefix = '') ⇒ Matcher
constructor
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.
- #missing_params?(*args) ⇒ Boolean
- #too_many_params?(*args) ⇒ Boolean
- #wrong_params_set?(*args) ⇒ Boolean
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
#params ⇒ Object (readonly)
Returns the value of attribute params.
4 5 6 |
# File 'lib/welo/core/matcher.rb', line 4 def params @params end |
#prefix ⇒ Object (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
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
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
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 |