Class: LIVR::Rules::String::LengthEqual

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

Instance Method Summary collapse

Constructor Details

#initialize(length) ⇒ LengthEqual


87
88
89
# File 'lib/livr/rules/string.rb', line 87

def initialize(length)
  @length = length
end

Instance Method Details

#call(value, user_data, field_results) ⇒ Object


91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/livr/rules/string.rb', line 91

def call(value, user_data, field_results)
  return if value.in? [nil, ""]
  return 'FORMAT_ERROR' unless is_primitive(value)

  value = value.to_s
  return 'TOO_SHORT' if value.length < @length
  return 'TOO_LONG'  if value.length > @length

  field_results << value

  return
end