Sha256: 922ef987f18c2800ed1b0e56e371f97208bde87c6714370a3b2d5ba60294c15e

Contents?: true

Size: 748 Bytes

Versions: 6

Compression:

Stored size: 748 Bytes

Contents

require_relative "./helpers/number_helper"

module JsonTestData
  class Number
    extend NumberHelper

    class << self
      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
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
json_test_data-0.5.1 lib/json_test_data/data_structures/number.rb
json_test_data-0.5.0 lib/json_test_data/data_structures/number.rb
json_test_data-0.4.0 lib/json_test_data/data_structures/number.rb
json_test_data-0.4.0.beta lib/json_test_data/data_structures/number.rb
json_test_data-0.3.0.beta lib/json_test_data/data_structures/number.rb
json_test_data-0.1.0 lib/json_test_data/data_structures/number.rb