Class: Calculon::MultiGroupingResults

Inherits:
Results
  • Object
show all
Defined in:
lib/calculon/results.rb

Instance Attribute Summary

Attributes inherited from Results

#rows

Instance Method Summary collapse

Methods inherited from Results

create, #groupings, #initialize, #map_each_time, #time_format

Constructor Details

This class inherits a constructor from Calculon::Results

Instance Method Details

#to_aObject



75
76
77
78
79
# File 'lib/calculon/results.rb', line 75

def to_a
  map_each_time { |key|
    fetch(key, [])
  }
end

#values_for(grouping, default = nil) ⇒ Object



81
82
83
84
85
86
# File 'lib/calculon/results.rb', line 81

def values_for(grouping, default=nil)
  map_each_time { |key|
    matches = fetch(key, []).select { |value| grouping.map { |k,v| value.send(k) == v }.all? }
    matches.length > 0 ? matches.first : default
  }
end