Sha256: 64b2c4a898215e32c762fdff4ec79e03f948c99808732538d4a47483fc978156

Contents?: true

Size: 869 Bytes

Versions: 3

Compression:

Stored size: 869 Bytes

Contents

module Fakeit
  module Openapi
    module Example
      BIG_INT = 2**32

      def integer_example
        if enum
          enum.to_a.sample
        else
          Faker::Number.between(int_rand_begin, int_rand_end) * int_multiple
        end
      end

      private

      def int_rand_begin
        min_int / int_multiple + int_rand_begin_adjust
      end

      def int_rand_end
        max_int / int_multiple
      end

      def int_rand_begin_adjust
        (min_int % int_multiple).zero? ? 0 : 1
      end

      def int_multiple
        multipleOf || 1
      end

      def min_int
        if minimum
          exclusiveMinimum ? minimum + 1 : minimum
        else
          1
        end
      end

      def max_int
        if maximum
          exclusiveMaximum ? maximum - 1 : maximum
        else
          BIG_INT
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fakeit-0.1.5 lib/fakeit/openapi/example/integer_example.rb
fakeit-0.1.4 lib/fakeit/openapi/example/integer_example.rb
fakeit-0.1.3 lib/fakeit/openapi/example/integer_example.rb