class FreeForm::DateParamsFilter
Public Class Methods
new(*args)
click to toggle source
# File lib/freeform/form/date_params_filter.rb, line 3 def initialize(*args) end
Public Instance Methods
call(params)
click to toggle source
# File lib/freeform/form/date_params_filter.rb, line 6 def call(params) date_attributes = {} params.each do |attribute, value| if value.is_a?(Hash) 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)") ) end end params.merge!(date_attributes) end
Private Instance Methods
params_to_date(year, month, day)
click to toggle source
# File lib/freeform/form/date_params_filter.rb, line 25 def params_to_date(year, month, day) day ||= 1 # FIXME: is that really what we want? test. begin # TODO: test fails. return Date.new(year.to_i, month.to_i, day.to_i) rescue ArgumentError => e return nil end end