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
73
74
75
76
77
78
79
80
|
# File 'lib/artirix_data_models/aggregations_factory.rb', line 73
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
82
83
84
|
# File 'lib/artirix_data_models/aggregations_factory.rb', line 82
def self.prepare_key(key)
key.to_s.strip.downcase
end
|
.sort_by_index_on(index_array) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/artirix_data_models/aggregations_factory.rb', line 86
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
|