Class: LIVR::Rules::String::Eq

Inherits:
LIVR::Rule show all
Defined in:
lib/livr/rules/string.rb

Instance Method Summary collapse

Constructor Details

#initialize(allowed_value) ⇒ Eq

Returns a new instance of Eq.



17
18
19
# File 'lib/livr/rules/string.rb', line 17

def initialize(allowed_value)
  @allowed_value = allowed_value
end

Instance Method Details

#call(value, user_data, field_results) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/livr/rules/string.rb', line 21

def call(value, user_data, field_results)
  return if is_no_value(value)
  return 'FORMAT_ERROR' unless is_primitive(value)

  if value.to_s == @allowed_value.to_s
    field_results << @allowed_value
    return
  end

  return 'NOT_ALLOWED_VALUE'
end