Sha256: f6d4761e9333f913e27e3fb01e1b5331652b09087f24cfefa6ff82530b803f75

Contents?: true

Size: 644 Bytes

Versions: 14

Compression:

Stored size: 644 Bytes

Contents

require 'haveapi/client/validator'

module HaveAPI::Client
  class Validators::Numericality < Validator
    name :number

    def valid?
      if value.is_a?(::String)
        return false if /\A\d+\z/ !~ value

        v = value.to_i

      else
        v = value
      end

      ret = true
      ret = false if opts[:min] && v < opts[:min]
      ret = false if opts[:max] && v > opts[:max]
      ret = false if opts[:step] && (v - (opts[:min] || 0)) % opts[:step] != 0
      ret = false if opts[:mod] && v % opts[:mod] != 0
      ret = false if opts[:odd] && v.even?
      ret = false if opts[:even] && v % 2 > 0
      ret
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
haveapi-client-0.25.0 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.24.0 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.23.7 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.23.6 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.23.5 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.23.4 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.23.3 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.23.2 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.23.1 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.23.0 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.22.1 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.22.0 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.21.1 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.21.0 lib/haveapi/client/validators/numericality.rb