data.sort_by { |a| [a['company'], a['country'], a['user']['name']] }
When sort_by
receives an array, it compares each element when the previous ones tie.
If you want to sort company ASC, country ASC, name ASC
and then easily reverse it to company DESC, country DESC, name ASC
you can do this:
sorted = data.group_by do |x|
[x['company'], x['country']]
end.each do |k, v|
v.sort_by! { |x| x[:user][:name] }
end.sort_by(&:first).map(&:last)
This creates an array of arrays, each internal array contains all the users in the company/country pair, sorted by name.
now to get the ASC option you should do:
sorted.flatten
and the reverse (where users are still ASC) you need to:
sorted.reverse.flatten