Class: LIVR::Rules::Numeric::PositiveDecimal

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

Instance Method Summary collapse

Methods inherited from LIVR::Rule

#initialize

Constructor Details

This class inherits a constructor from LIVR::Rule

Instance Method Details

#call(value, user_data, field_results) ⇒ Object


51
52
53
54
55
56
57
58
59
60
61
# File 'lib/livr/rules/numeric.rb', line 51

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

  value_float = Float(value.to_s) rescue nil
  return "NOT_POSITIVE_DECIMAL" if value_float.nil?
  return "NOT_POSITIVE_DECIMAL" unless value_float.positive?

  field_results << value_float
  return
end