Class: Realize::Logical::Switch::Case

Inherits:
Object
  • Object
show all
Includes:
Arrays
Defined in:
lib/realize/logical/switch/case.rb

Overview

This class encapsulates and defines what a switch case statement is. The values attribute is a list of values to test. The transformers are the transformers to execute if the value matches.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Arrays

#array

Constructor Details

#initialize(values: [], transformers: []) ⇒ Case

Returns a new instance of Case.



22
23
24
25
# File 'lib/realize/logical/switch/case.rb', line 22

def initialize(values: [], transformers: [])
  @values       = array(values).map(&:to_s).to_set
  @transformers = Transformers.array(transformers)
end

Instance Attribute Details

#transformersObject (readonly)

Returns the value of attribute transformers.



20
21
22
# File 'lib/realize/logical/switch/case.rb', line 20

def transformers
  @transformers
end

#valuesObject (readonly)

Returns the value of attribute values.



20
21
22
# File 'lib/realize/logical/switch/case.rb', line 20

def values
  @values
end

Instance Method Details

#match?(value) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/realize/logical/switch/case.rb', line 27

def match?(value)
  values.include?(value.to_s)
end