Method: Dynamini::TestClient#sort_records

Defined in:
lib/dynamini/test_client.rb

#sort_records(records, index, args, start_val, end_val) ⇒ Object



176
177
178
179
180
181
182
183
184
# File 'lib/dynamini/test_client.rb', line 176

def sort_records(records, index, args, start_val, end_val)
  records = records.select { |record| record[get_secondary_hash_key(index)] == hash_key_value(args) }
  records = records.select { |record| record[get_secondary_range_key(index)] >= start_val.to_f } if start_val
  records = records.select { |record| record[get_secondary_range_key(index)] <= end_val.to_f } if end_val
  records = records.sort { |a, b| a[get_secondary_range_key(index)] <=> b[get_secondary_range_key(index)] }
  records = records.reverse if args[:scan_index_forward] == false
  records = records[0...args[:limit]] if args[:limit]
  records
end