Class: RailsPerformance::Models::Collection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCollection

Returns a new instance of Collection.



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

def initialize
  @data = []
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

Instance Method Details

#add(record) ⇒ Object



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

def add(record)
  @data << record
end

#fetch_values(groupped_collection) ⇒ Object



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

def fetch_values(groupped_collection)
  result = {}
  groupped_collection.each do |key, records|
    result[key] ||= []
    records.each do |record|
      result[key] << record.value
    end
  end
  result
end

#group_by(type) ⇒ Object



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

def group_by(type)
  case type
  when :controller_action, :controller_action_format, :datetime, :path
    fetch_values @data.group_by(&type)
  else
    {}
  end
end