class SoberSwag::Reporting::Input::MultipleOf

Adds the multipleOf constraint to input types. Will use the '%' operator to calculate this, which may behave oddly for floats.

Attributes

input[R]

@return [Interface]

mult[R]

@return [Numeric]

Public Class Methods

new(input, mult) click to toggle source
# File lib/sober_swag/reporting/input/multiple_of.rb, line 8
def initialize(input, mult)
  @input = input
  @mult = mult
end

Public Instance Methods

call(value) click to toggle source
# File lib/sober_swag/reporting/input/multiple_of.rb, line 21
def call(value)
  parsed = input.call(value)

  return parsed if parsed.is_a?(Report::Base)
  return Report::Value.new(["was not a multiple of #{mult}"]) unless (parsed % mult).zero?

  parsed
end
swagger_schema() click to toggle source
# File lib/sober_swag/reporting/input/multiple_of.rb, line 30
def swagger_schema
  modify_schema(input, { multipleOf: mult })
end