Class: Realize::Logical::Switch::Case
- Inherits:
-
Object
- Object
- Realize::Logical::Switch::Case
- 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
-
#transformers ⇒ Object
readonly
Returns the value of attribute transformers.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
-
#initialize(values: [], transformers: []) ⇒ Case
constructor
A new instance of Case.
- #match?(value) ⇒ Boolean
Methods included from Arrays
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
#transformers ⇒ Object (readonly)
Returns the value of attribute transformers.
20 21 22 |
# File 'lib/realize/logical/switch/case.rb', line 20 def transformers @transformers end |
#values ⇒ Object (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
27 28 29 |
# File 'lib/realize/logical/switch/case.rb', line 27 def match?(value) values.include?(value.to_s) end |