Class: LIVR::Rules::String::OneOf
- Inherits:
-
LIVR::Rule
- Object
- LIVR::Rule
- LIVR::Rules::String::OneOf
- Defined in:
- lib/livr/rules/string.rb
Instance Method Summary collapse
- #call(value, user_data, field_results) ⇒ Object
-
#initialize(*allowed_values) ⇒ OneOf
constructor
A new instance of OneOf.
Constructor Details
#initialize(*allowed_values) ⇒ OneOf
Returns a new instance of OneOf.
35 36 37 |
# File 'lib/livr/rules/string.rb', line 35 def initialize(*allowed_values) @allowed_values = allowed_values.flatten end |
Instance Method Details
#call(value, user_data, field_results) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/livr/rules/string.rb', line 39 def call(value, user_data, field_results) return if is_no_value(value) return 'FORMAT_ERROR' unless is_primitive(value) @allowed_values.each do |allowed_value| if allowed_value.to_s == value.to_s field_results << allowed_value return end end return 'NOT_ALLOWED_VALUE' end |