Module: ArtirixDataModels::AggregationsFactory::SortedBucketsAggregationClassFactory
- Defined in:
- lib/artirix_data_models/aggregations_factory.rb
Defined Under Namespace
Classes: SortedBucketAggregationBase
Class Method Summary
collapse
Class Method Details
.build_class_based_on_index_on(index_array) ⇒ Object
80
81
82
83
84
85
86
87
|
# 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) ⇒ Object
89
90
91
|
# 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) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# 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
|