Class: EightBall::Conditions::List

Inherits:
Base
  • Object
show all
Defined in:
lib/eight_ball/conditions/list.rb

Overview

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

Instance Attribute Summary collapse

Attributes inherited from Base

#parameter

Instance Method Summary collapse

Methods inherited from Base

#==, #hash

Constructor Details

#initialize(options = {}) ⇒ List

Creates a new instance of a List Condition.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :values (Array<String>, String)

    The list of acceptable values

  • :parameter (String)

    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?.



19
20
21
22
23
24
# File 'lib/eight_ball/conditions/list.rb', line 19

def initialize(options = {})
  options ||= {}

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

Instance Attribute Details

#valuesObject (readonly)

Returns the value of attribute values.



7
8
9
# File 'lib/eight_ball/conditions/list.rb', line 7

def values
  @values
end

Instance Method Details

#satisfied?(value) ⇒ Boolean

Examples:

condition = new EightBall::Conditions::List.new [1, 'a']
condition.satisfied? 1 => true
condition.satisfied? 2 => false
condition.satisfied? 'a' => true

Returns:

  • (Boolean)


31
32
33
# File 'lib/eight_ball/conditions/list.rb', line 31

def satisfied?(value)
  values.include? value
end