Class: ArtirixDataModels::Aggregation

Inherits:
CommonAggregation show all
Includes:
Enumerable
Defined in:
lib/artirix_data_models/aggregation.rb

Defined Under Namespace

Classes: Value

Constant Summary

Constants included from Inspectable

Inspectable::SPACE

Instance Attribute Summary collapse

Attributes inherited from CommonAggregation

#name

Instance Method Summary collapse

Methods inherited from CommonAggregation

from_json, #pretty_name

Methods included from Inspectable

#data_hash_for_inspect, #inspect, #inspect_with_tab

Constructor Details

#initialize(name, buckets) ⇒ Aggregation

Returns a new instance of Aggregation.



34
35
36
37
# File 'lib/artirix_data_models/aggregation.rb', line 34

def initialize(name, buckets)
  super name
  @buckets = buckets
end

Instance Attribute Details

#bucketsObject

Returns the value of attribute buckets.



32
33
34
# File 'lib/artirix_data_models/aggregation.rb', line 32

def buckets
  @buckets
end

Instance Method Details

#calculate_filtered(filtered_values = []) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/artirix_data_models/aggregation.rb', line 52

def calculate_filtered(filtered_values = [])
  buckets.each do |b|
    b.filtered = filtered_values.include?(b.name)
  end

  self
end

#data_hashObject



45
46
47
48
49
50
# File 'lib/artirix_data_models/aggregation.rb', line 45

def data_hash
  {
    name:    name,
    buckets: buckets.map(&:data_hash)
  }
end

#filtered_bucketsObject



60
61
62
# File 'lib/artirix_data_models/aggregation.rb', line 60

def filtered_buckets
  buckets.select &:filtered?
end

#filtered_first_bucketsObject



68
69
70
# File 'lib/artirix_data_models/aggregation.rb', line 68

def filtered_first_buckets
  filtered_buckets + unfiltered_buckets
end

#non_empty_bucketsObject



41
42
43
# File 'lib/artirix_data_models/aggregation.rb', line 41

def non_empty_buckets
  buckets.reject { |x| x.empty? }
end

#unfiltered_bucketsObject



64
65
66
# File 'lib/artirix_data_models/aggregation.rb', line 64

def unfiltered_buckets
  buckets.reject &:filtered?
end