Class: RailsPerformance::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_performance/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCollection



5
6
7
# File 'lib/rails_performance/collection.rb', line 5

def initialize
  @data = []
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/rails_performance/collection.rb', line 3

def data
  @data
end

Instance Method Details

#add(record) ⇒ Object



9
10
11
# File 'lib/rails_performance/collection.rb', line 9

def add(record)
  @data << record
end

#group_by(type) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/rails_performance/collection.rb', line 13

def group_by(type)
  @data = case type
  when :controller_action, :controller_action_format, :datetime, :path
    @data.group_by(&type)
  else
    []
  end
  self
end

#valuesObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rails_performance/collection.rb', line 23

def values
  return [] if @data.empty?
  result = {}
  @data.each do |key, records|
    result[key] ||= []
    records.each do |record|
      result[key] << record.value
    end
  end
  result
end