module ArtirixDataModels::AggregationsFactory::SortedBucketsAggregationClassFactory

Public Class Methods

build_class_based_on_index_on(index_array) click to toggle source
# File lib/artirix_data_models/aggregations_factory.rb, line 80
def self.build_class_based_on_index_on(index_array)
  prepared_index_array = index_array.map { |key| SortedBucketsAggregationClassFactory.prepare_key(key) }
  sort_by_proc         = sort_by_index_on(prepared_index_array)

  Class.new(SortedBucketAggregationBase).tap do |klass|
    klass.sort_by_callable = sort_by_proc
  end
end
prepare_key(key) click to toggle source
# File lib/artirix_data_models/aggregations_factory.rb, line 89
def self.prepare_key(key)
  key.to_s.strip.downcase
end
sort_by_index_on(index_array) click to toggle source
# File lib/artirix_data_models/aggregations_factory.rb, line 93
def self.sort_by_index_on(index_array)
  proc do |bucket|
    name = SortedBucketsAggregationClassFactory.prepare_key(bucket.name)

    found_index = index_array.index(name)

    if found_index.present?
      [0, found_index]
    else
      [1, 0]
    end
  end
end