Sha256: 24d6952e56bec5430aba80e9245b39f02bd287fdc6e594e331529e1add964686

Contents?: true

Size: 962 Bytes

Versions: 6

Compression:

Stored size: 962 Bytes

Contents

module Fakeit
  module Openapi
    module Example
      MIN_NUM = -2**31
      MAX_NUM = 2**31 - 1

      def number_example(example_options)
        if example_options[:use_static][type: 'number', property: example_options[:property]]
          static_number_example
        else
          random_number_example
        end
      end

      private

      def static_number_example = (num_rand_end * num_multiple).then { multipleOf ? _1 : _1.round(2) }

      def random_number_example
        (Faker::Number.between(from: num_rand_begin, to: num_rand_end) * num_multiple)
          .then { multipleOf ? _1 : _1.round(2) }
      end

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

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

      def num_multiple = multipleOf || 1

      def min_num = (minimum || MIN_NUM).to_f.ceil(2)

      def max_num = (maximum || MAX_NUM).to_f.floor(2)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fakeit-0.10.0 lib/fakeit/openapi/example/number_example.rb
fakeit-0.9.2 lib/fakeit/openapi/example/number_example.rb
fakeit-0.9.1 lib/fakeit/openapi/example/number_example.rb
fakeit-0.9.0 lib/fakeit/openapi/example/number_example.rb
fakeit-0.8.1 lib/fakeit/openapi/example/number_example.rb
fakeit-0.8.0 lib/fakeit/openapi/example/number_example.rb