Sha256: 5fb9dc6acdd48bf3f5779cf79ae05ea3110fee31312b2c9b1e81498a6ccd4577

Contents?: true

Size: 611 Bytes

Versions: 3

Compression:

Stored size: 611 Bytes

Contents

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

      def number_example
        (Faker::Number.between(num_rand_begin, num_rand_end) * num_multiple).round(2)
      end

      private

      def num_rand_begin
        multipleOf ? (min_num / multipleOf).ceil : min_num
      end

      def num_rand_end
        multipleOf ? (max_num / multipleOf).floor : max_num
      end

      def num_multiple
        multipleOf || 1
      end

      def min_num
        (minimum || 0).to_f.ceil(2)
      end

      def max_num
        (maximum || BIG_NUM).to_f.floor(2)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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