class Shipwire::ParamConverter
Attributes
params[R]
Public Class Methods
new(params)
click to toggle source
# File lib/shipwire/param_converter.rb, line 5 def initialize(params) if params.is_a?(Array) @params = params.each_with_object([]) do |item, hsh| hsh << recursively_struct(item) end else @params = recursively_struct(params) end end
Public Instance Methods
to_h()
click to toggle source
# File lib/shipwire/param_converter.rb, line 15 def to_h if params.is_a?(Array) params.each_with_object([]) do |item, hsh| hsh << with_object(item) end else with_object(params) end end
Private Instance Methods
recursively_struct(item)
click to toggle source
# File lib/shipwire/param_converter.rb, line 27 def recursively_struct(item) RecursiveOpenStruct.new(item, recurse_over_arrays: true).to_h end
with_object(item)
click to toggle source
# File lib/shipwire/param_converter.rb, line 31 def with_object(item) item.each_with_object({}) do |(original_key, value), hsh| key = Utility.camelize(original_key.to_s, :lower).to_sym hsh[key] = value.is_a?(Hash) ? with_object(value) : value end end