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 WithDAORegistry

WithDAORegistry::DEFAULT_DAO_REGISTRY_LOADER

Constants included from Inspectable

Inspectable::SPACE

Instance Attribute Summary collapse

Attributes inherited from CommonAggregation

#name

Attributes included from WithDAORegistry

#dao_registry_loader

Instance Method Summary collapse

Methods inherited from CommonAggregation

from_json, #pretty_name

Methods included from WithDAORegistry

#dao_registry, #dao_registry=, #default_dao_registry, loader_or_registry_or_default, #set_dao_registry, #set_dao_registry_and_loader, #set_dao_registry_loader, #set_default_dao_registry_loader

Methods included from Inspectable

#data_hash_for_inspect, #inspect, #inspect_with_tab

Constructor Details

#initialize(name, buckets) ⇒ Aggregation

Returns a new instance of Aggregation.



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

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

Instance Attribute Details

#bucketsObject

Returns the value of attribute buckets.



37
38
39
# File 'lib/artirix_data_models/aggregation.rb', line 37

def buckets
  @buckets
end

Instance Method Details

#calculate_filtered(filtered_values = []) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/artirix_data_models/aggregation.rb', line 57

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

  self
end

#data_hashObject



50
51
52
53
54
55
# File 'lib/artirix_data_models/aggregation.rb', line 50

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

#filtered_bucketsObject



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

def filtered_buckets
  buckets.select &:filtered?
end

#filtered_first_bucketsObject



73
74
75
# File 'lib/artirix_data_models/aggregation.rb', line 73

def filtered_first_buckets
  filtered_buckets + unfiltered_buckets
end

#non_empty_bucketsObject



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

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

#unfiltered_bucketsObject



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

def unfiltered_buckets
  buckets.reject &:filtered?
end