Class: LIVR::Rules::Numeric::MaxNumber

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

Instance Method Summary collapse

Constructor Details

#initialize(max_number) ⇒ MaxNumber

Returns a new instance of MaxNumber.



65
66
67
# File 'lib/livr/rules/numeric.rb', line 65

def initialize(max_number)
  @max_number = max_number
end

Instance Method Details

#call(value, user_data, field_results) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/livr/rules/numeric.rb', line 69

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

  if value > @max_number
    return "TOO_HIGH"
  else
    field_results << value
    return
  end
end