Class: Reynard::GroupedParameters

Inherits:
Object
  • Object
show all
Defined in:
lib/reynard/grouped_parameters.rb

Overview

Groups parameters based on the parameters specification.

Instance Method Summary collapse

Constructor Details

#initialize(specification, params) ⇒ GroupedParameters

Returns a new instance of GroupedParameters.



6
7
8
9
# File 'lib/reynard/grouped_parameters.rb', line 6

def initialize(specification, params)
  @specification = pivot(specification)
  @params = params
end

Instance Method Details

#to_hObject



11
12
13
14
15
16
17
# File 'lib/reynard/grouped_parameters.rb', line 11

def to_h
  @params.each_with_object({}) do |(name, value), grouped|
    group_name = @specification.dig(name, 'in') || 'query'
    grouped[group_name] ||= {}
    grouped[group_name].merge!({ name => value })
  end
end