I have this data with me:
[{:id=>250,
:application_date=>"02/04/2016",
:customer_number=>"",
:customer_name=>"Neymar Silva Junior",
:city=>"Auckland",
:region=>"Auckland",
:service=>"Electricity",
:name=>"Bosco and Sons",
:service_plan=>"Electricity Plan",
:connection_type=>nil,
:billing_method=>nil,
:icp_number=>nil,
:moving_date=>"",
:supplier_commission=>21.0,
:show_url=>"/applications/250"},
{:id=>257,
:application_date=>"27/05/2016",
:customer_number=>"",
:customer_name=>"Ariel name Parra",
:city=>"Dunedin",
:region=>"Dunedin",
:service=>"Electricity",
:name=>"Bosco and Sons",
:service_plan=>"Electricity Plan",
:connection_type=>nil,
:billing_method=>nil,
:icp_number=>nil,
:moving_date=>"28/05/2016",
:supplier_commission=>21.0,
:show_url=>"/applications/257"},
{:id=>291,
:application_date=>"29/04/2016",
:customer_number=>"aaaa",
:customer_name=>"Neymar Silva Junior",
:city=>"Auckland",
:region=>"Auckland",
:service=>"Electricity",
:name=>"Bosco and Sons",
:service_plan=>"Electricity Plan",
:connection_type=>nil,
:billing_method=>nil,
:icp_number=>"",
:moving_date=>"",
:supplier_commission=>28.0,
:show_url=>"/applications/291"},
{:id=>292,
:application_date=>"29/04/2016",
:customer_number=>"23223",
:customer_name=>"Neymar Silva Junior",
:city=>"Auckland",
:region=>"Auckland",
:service=>"Electricity",
:name=>"Bosco and Sons",
:service_plan=>"Electricity Plan",
:connection_type=>nil,
:billing_method=>nil,
:icp_number=>"",
:moving_date=>"",
:supplier_commission=>21.0,
:show_url=>"/applications/292"}]
I want to sort this data in two different ways, alphabetically(from A to Z) as well as Recursively(Z to A) according to its attributes in following scenarios:
If the sort parameter is
service_planalphabetically it will sort as per this attribute from A to Z, if recursively then Z to A for this attribute and so on for all attributes.Idis integer so it should be sorted in increasing or decreasing order.Moreover the nil value should not through an error and should be present in the result.
Thanks in advance!