Validates and converts parameters. Also it converts all keys to symbols.
To install it, add the gem to your Gemfile:
gem 'spine-parameters'
Then run bundle
. If you're not using Bundler, just gem install spine-parameters
.
parameters = Spine::Parameters::Collection.new(parameters_containing_hash)
parameters.required(:name)
.integer(:id)
.timestamp(:since)
.boolean(:valid)
.list(:favourites)
parameters.errors? # Checks if there is any parsing error.
parameters.errors
# => { id: ['invalid number'] }
parameters[:since]
# => <DateTime: 2014-01-01T12:00:00+00:00>