Sha256: d22e2a1bacd5d40b1aaa7db9272b35de68fe3f94d7fb0f52458e1f129bacd4e4

Contents?: true

Size: 610 Bytes

Versions: 16

Compression:

Stored size: 610 Bytes

Contents

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 % 2 == 0
      ret = false if opts[:even] && v % 2 > 0
      ret
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
haveapi-client-0.11.1 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.11.0 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.10.0 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.9.0 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.8.0 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.7.1 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.7.0 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.6.0 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.5.4 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.5.3 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.5.2 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.5.1 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.5.0 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.4.2 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.4.1 lib/haveapi/client/validators/numericality.rb
haveapi-client-0.4.0 lib/haveapi/client/validators/numericality.rb