lib/fakeit/openapi/example/number_example.rb in fakeit-0.1.2 vs lib/fakeit/openapi/example/number_example.rb in fakeit-0.1.3
- old
+ new
@@ -2,13 +2,25 @@
module Openapi
module Example
BIG_NUM = 2**32
def number_example
- Faker::Number.between(min_num, max_num).round(2)
+ (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