Skip to content

Instantly share code, notes, and snippets.

@ljkbennett
ljkbennett / gist:5495596
Last active December 16, 2015 20:49 — forked from durran/gist:315227
module MultiParameterAttributes
def filter_time(attributes, name)
attrs = attributes.collect do |key, value|
if key =~ /^#{Regexp.escape(name.to_s)}\((\d+)(\w)\)$/
[$1.to_i, value.send("to_#$2")]
end
end.compact.sort_by(&:first).map(&:last)
attributes.reject! {|key,value| key =~ /^#{Regexp.escape(name.to_s)}\((\d+)(\w)\)$/ }
attributes[name] = Time.zone.local(*attrs) unless attrs.empty?