class EightBall::Conditions::List

The List Condition describes a list of acceptable values. These can be strings, integers, etc.

Attributes

values[R]

Public Class Methods

new(options = {}) click to toggle source

Creates a new instance of a List Condition.

@param [Hash] options

@option options [Array<String>, String] :values

The list of acceptable values

@option options [String] :parameter

The name of the parameter this Condition was created for (eg. "account_id").
This value is only used by calling classes as a way to know what to pass
into {satisfied?}.
# File lib/eight_ball/conditions/list.rb, line 19
def initialize(options = {})
  options ||= {}

  @values = Array(options[:values])
  self.parameter = options[:parameter]
end

Public Instance Methods

satisfied?(value) click to toggle source

@example

condition = new EightBall::Conditions::List.new [1, 'a']
condition.satisfied? 1 => true
condition.satisfied? 2 => false
condition.satisfied? 'a' => true
# File lib/eight_ball/conditions/list.rb, line 31
def satisfied?(value)
  values.include? value
end

Protected Instance Methods

state() click to toggle source
Calls superclass method EightBall::Conditions::Base#state
# File lib/eight_ball/conditions/list.rb, line 37
def state
  super + [@values.sort]
end