Class: EightBall::Conditions::List
- 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
-
#coerce ⇒ Object
readonly
Returns the value of attribute coerce.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ List
constructor
Creates a new instance of a List Condition.
- #satisfied?(value) ⇒ Boolean
- #wire_fields ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ List
Creates a new instance of a List Condition.
22 23 24 25 26 27 28 29 |
# File 'lib/eight_ball/conditions/list.rb', line 22 def initialize( = {}) ||= {} @values = Array([:values]) # Store a canonical true/nil so the wire never carries a stray non-boolean. @coerce = [:coerce] ? true : nil self.parameter = [:parameter] end |
Instance Attribute Details
#coerce ⇒ Object (readonly)
Returns the value of attribute coerce.
7 8 9 |
# File 'lib/eight_ball/conditions/list.rb', line 7 def coerce @coerce end |
#values ⇒ Object (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
36 37 38 39 40 41 42 43 |
# File 'lib/eight_ball/conditions/list.rb', line 36 def satisfied?(value) if @coerce string_value = value.to_s return values.any? { |v| v.to_s == string_value } end values.include? value end |
#wire_fields ⇒ Object
45 46 47 48 49 |
# File 'lib/eight_ball/conditions/list.rb', line 45 def wire_fields # coerce before parameter so the wire key order matches the eight-ball-ts # port (whose parameter is always emitted last), keeping the two byte-identical. %i[values coerce parameter] end |