Class: SoberSwag::Reporting::Input::MultipleOf

Inherits:
Base
  • Object
show all
Defined in:
lib/sober_swag/reporting/input/multiple_of.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Interface

#add_schema_key, #call!, #described, #enum, #format, #in_range, #list, #mapped, #modify_schema, #multiple_of, #optional, #or, #referenced, #swagger_path_schema, #swagger_query_schema, #|

Constructor Details

#initialize(input, mult) ⇒ MultipleOf

Returns a new instance of MultipleOf.



8
9
10
11
# File 'lib/sober_swag/reporting/input/multiple_of.rb', line 8

def initialize(input, mult)
  @input = input
  @mult = mult
end

Instance Attribute Details

#inputInterface (readonly)

Returns:



15
16
17
# File 'lib/sober_swag/reporting/input/multiple_of.rb', line 15

def input
  @input
end

#multNumeric (readonly)

Returns:

  • (Numeric)


19
20
21
# File 'lib/sober_swag/reporting/input/multiple_of.rb', line 19

def mult
  @mult
end

Instance Method Details

#call(value) ⇒ Object



21
22
23
24
25
26
27
28
# 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_schemaObject



30
31
32
# File 'lib/sober_swag/reporting/input/multiple_of.rb', line 30

def swagger_schema
  modify_schema(input, { multipleOf: mult })
end