class LIVR::Rules::String::OneOf
Public Class Methods
new(*allowed_values)
click to toggle source
# File lib/livr/rules/string.rb, line 35 def initialize(*allowed_values) @allowed_values = allowed_values.flatten end
Public Instance Methods
call(value, user_data, field_results)
click to toggle source
# 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