Sha256: 75a65d48299039c1ac2667f2d7170f0956d99e46885fe8951170f78b48048419
Contents?: true
Size: 639 Bytes
Versions: 6
Compression:
Stored size: 639 Bytes
Contents
class MultipleOfValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) return if value.blank? #tolerance = options[:tolerance] || 0.00001 #puts %(#{value} % #{options[:of]}=#{(value % options[:of]).inspect}) #unless BigDecimal.new(value) % BigDecimal.new(options[:of]) <= tolerance begin unless BigDecimal.new(value.to_s) % BigDecimal.new(options[:of].to_s) == BigDecimal.new('0.0') record.errors.add attribute, :not_multiple_of, of: options[:of] end rescue puts "#{$!} for either #{value.inspect} or #{options[:of].inspect}" return end end end
Version data entries
6 entries across 6 versions & 1 rubygems