Class: JsonTestData::Number
- Inherits:
-
Object
- Object
- JsonTestData::Number
- Extended by:
- NumberHelper
- Defined in:
- lib/json_test_data/data_structures/number.rb
Class Method Summary collapse
Methods included from NumberHelper
adjust_for_maximum, adjust_for_minimum, between, mean
Class Method Details
.create(schema) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/json_test_data/data_structures/number.rb', line 8 def create(schema) factor = schema.fetch(:multipleOf, nil) minimum, maximum = schema.fetch(:minimum, nil), schema.fetch(:maximum, nil) num = if maximum && minimum between(min: minimum, max: maximum, integer: schema.fetch(:type) == "") else factor || 1 end step_size = schema.fetch(:type) == "integer" ? 1 : 0.5 num = adjust_for_maximum(number: num, maximum: maximum, step_size: factor || step_size) adjust_for_minimum(number: num, minimum: minimum, step_size: factor || step_size) end |