Class: LIVR::Rules::Numeric::NumberBetween

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

Instance Method Summary collapse

Constructor Details

#initialize(min_number, max_number) ⇒ NumberBetween

Returns a new instance of NumberBetween.



111
112
113
114
# File 'lib/livr/rules/numeric.rb', line 111

def initialize(min_number, max_number)
  @min_number = min_number
  @max_number = max_number
end

Instance Method Details

#call(value, user_data, field_results) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/livr/rules/numeric.rb', line 116

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

  value = Float(value.to_s) rescue nil
  if value.nil?
    return "NOT_NUMBER"
  end


  return "TOO_LOW"  if value < @min_number
  return "TOO_HIGH" if value > @max_number

  field_results << value
  return
end