Module: Finlight::Params
- Defined in:
- lib/finlight/params.rb
Overview
Converts idiomatic snake_case Ruby keyword arguments into the camelCase JSON wire format, omitting unset (nil) fields. Keys that are already camelCase pass through unchanged.
Class Method Summary collapse
-
.camelize(key) ⇒ Object
page_size -> pageSize, exclude_sources -> excludeSources, from -> from.
- .normalize(params) ⇒ Hash{String => Object}
Class Method Details
.camelize(key) ⇒ Object
page_size -> pageSize, exclude_sources -> excludeSources, from -> from
21 22 23 |
# File 'lib/finlight/params.rb', line 21 def camelize(key) key.to_s.gsub(/_([a-z0-9])/) { Regexp.last_match(1).upcase } end |
.normalize(params) ⇒ Hash{String => Object}
12 13 14 15 16 17 18 |
# File 'lib/finlight/params.rb', line 12 def normalize(params) params.each_with_object({}) do |(key, value), out| next if value.nil? out[camelize(key)] = value end end |