Class: EnumStateMachine::BlacklistMatcher

Inherits:
Matcher
  • Object
show all
Defined in:
lib/enum_state_machine/matcher.rb

Overview

Matches everything but a specific set of values

Instance Attribute Summary

Attributes inherited from Matcher

#values

Instance Method Summary collapse

Methods inherited from Matcher

#initialize

Constructor Details

This class inherits a constructor from EnumStateMachine::Matcher

Instance Method Details

#descriptionObject

A human-readable description of this matcher



96
97
98
# File 'lib/enum_state_machine/matcher.rb', line 96

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



91
92
93
# File 'lib/enum_state_machine/matcher.rb', line 91

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 = EnumStateMachine::BlacklistMatcher.new([:parked, :idling])
matcher.matches?(:parked)       # => false
matcher.matches?(:first_gear)   # => true

Returns:

  • (Boolean)


85
86
87
# File 'lib/enum_state_machine/matcher.rb', line 85

def matches?(value, context = {})
  !values.include?(value)
end