Class: StateMachines::BlacklistMatcher
- Defined in:
- lib/state_machines/matcher.rb
Overview
Matches everything but a specific set of values
Instance Attribute Summary
Attributes inherited from Matcher
Instance Method Summary collapse
-
#description ⇒ Object
A human-readable description of this matcher.
-
#filter(values) ⇒ Object
Finds all values that are not within the blacklist configured for this matcher.
-
#matches?(value, _context = {}) ⇒ Boolean
Checks whether the given value exists outside the blacklist configured for this matcher.
Methods inherited from Matcher
Constructor Details
This class inherits a constructor from StateMachines::Matcher
Instance Method Details
#description ⇒ Object
A human-readable description of this matcher
97 98 99 |
# File 'lib/state_machines/matcher.rb', line 97 def description "all - #{values.length == 1 ? values.first.inspect : values.inspect}" end |
#filter(values) ⇒ Object
Finds all values that are not within the blacklist configured for this matcher
92 93 94 |
# File 'lib/state_machines/matcher.rb', line 92 def filter(values) values - self.values end |
#matches?(value, _context = {}) ⇒ Boolean
Checks whether the given value exists outside the blacklist configured for this matcher.
Examples
matcher = StateMachines::BlacklistMatcher.new([:parked, :idling])
matcher.matches?(:parked) # => false
matcher.matches?(:first_gear) # => true
86 87 88 |
# File 'lib/state_machines/matcher.rb', line 86 def matches?(value, _context = {}) !values.include?(value) end |