class NRB::BeerXML::RecordValidators::PercentageValidator
Private Instance Methods
greater_than_min(value)
click to toggle source
# File lib/nrb/beerxml/record_validators/percentage_validator.rb, line 30 def greater_than_min(value) options[:allow_negative] ? true : value >= min end
less_than_max(value)
click to toggle source
# File lib/nrb/beerxml/record_validators/percentage_validator.rb, line 35 def less_than_max(value) options[:give_110] ? true : value <= max end
max()
click to toggle source
# File lib/nrb/beerxml/record_validators/percentage_validator.rb, line 40 def max options[:max] || 100 end
min()
click to toggle source
# File lib/nrb/beerxml/record_validators/percentage_validator.rb, line 45 def min options[:min] || 0 end
validate_each(record, attribute, value)
click to toggle source
# File lib/nrb/beerxml/record_validators/percentage_validator.rb, line 6 def validate_each(record, attribute, value) return unless value unless value.is_a?(Numeric) && greater_than_min(value) && less_than_max(value) message = 'must be a percentage' if options[:allow_negative] && options[:give_110] elsif options[:allow_negative] message += ' (greater than 0)' elsif options[:give_110] message += ' (less than 100)' else message += ' (between 0 & 100)' end record.errors[attribute] << message end end