Sorting records in Dynarex

require 'dynarex'

Dynarex.new('tags/tag(name, count)')
{Egypt: 45, UK: 103, France: 56, Belgium: 53, Ireland: 49, China: 256, \
Somalia: 21}.each {|country, count| dynarex.create name: country, count: count }

dynarex.to_h.sort_by {|x| -x[:count].to_i}.take(5).map{|x| x[:name]}.join(', ')
#=> "China, UK, France, Belgium, Ireland"

Obviously it would be easier in this example to just use a hash without Dynarex however there are times when I need to use Dynarex as the data source instead of a hash.

Tags:
Source:
1500hrs.txt
Published:
13-10-2011 15:00