Class: Reform::Form::MultiParameterAttributes::DateTimeParamsFilter
- Inherits:
-
Object
- Object
- Reform::Form::MultiParameterAttributes::DateTimeParamsFilter
- Defined in:
- lib/reform/form/multi_parameter_attributes.rb
Overview
TODO: implement this with parse_filter, so we don’t have to manually walk through the hash, etc.
Instance Method Summary collapse
Instance Method Details
#call(params) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/reform/form/multi_parameter_attributes.rb', line 4 def call(params) params = params.dup # DISCUSS: not sure if that slows down form processing? date_attributes = {} params.each do |attribute, value| if value.is_a?(Hash) params[attribute] = call(value) # TODO: #validate should only handle local form params. elsif matches = attribute.match(/^(\w+)\(.i\)$/) date_attribute = matches[1] date_attributes[date_attribute] = params_to_date( params.delete("#{date_attribute}(1i)"), params.delete("#{date_attribute}(2i)"), params.delete("#{date_attribute}(3i)"), params.delete("#{date_attribute}(4i)"), params.delete("#{date_attribute}(5i)") ) end end date_attributes.each do |attribute, date| params[attribute] = date end params end |