Sha256: 94ca6168b6f630808b1599b7a984700f5a5ca340b344113ddaf1e2323d9c1d9c

Contents?: true

Size: 770 Bytes

Versions: 9

Compression:

Stored size: 770 Bytes

Contents

module OpenActive
  module Validators
    class NumberValidator < BaseValidator
      # Coerce given value to the type the validator is validating against.
      # PLEASE NOTE: no checks are performed on the given value.
      # It is therefore recommended to call the "run" method first before this.
      #
      # @param value [mixed] The value to coerce.
      # @return [float] The coerced value
      def coerce(value)
        BigDecimal(value.to_s)
      end

      # Run validation on the given value.
      #
      # @param value [mixed] The value to validate.
      # @return [Boolean] Whether validation passes or not.
      def run(value)
        BigDecimal(value.to_s)
        true
      rescue ArgumentError => _e
        false
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
openactive-0.4.0 lib/openactive/validators/number_validator.rb
openactive-0.3.0 lib/openactive/validators/number_validator.rb
openactive-0.2.2 lib/openactive/validators/number_validator.rb
openactive-0.2.1 lib/openactive/validators/number_validator.rb
openactive-0.2.0 lib/openactive/validators/number_validator.rb
openactive-0.1.2 lib/openactive/validators/number_validator.rb
openactive-0.1.1 lib/openactive/validators/number_validator.rb
openactive-0.1.0 lib/openactive/validators/number_validator.rb
openactive-0.1.0.rc1 lib/openactive/validators/number_validator.rb