Currently a filter
parameter of a GET request is used to designate items' categories that will be requested from database and displayed.
The parameter contains comma delimited string - each string id for each category: filter=complete,inwork,cancelled,ycancelled
.
I want to get a Ruby object with corresponding attributes that will be true
or false
dependent on string id presence in filter
parameter. Current implementation is as follows:
filter = params[:filter].split(',') rescue []
fopt = OpenStruct.new(Hash[%w(complete inwork cancelled ycancelled).map {|fo| [fo.to_sym, filter.include?(fo)]}])
Could this be rewritten in shorter way?