Class: Railswatch::Models::Collection
- Inherits:
-
Object
- Object
- Railswatch::Models::Collection
- Defined in:
- lib/railswatch/models/collection.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #add(record) ⇒ Object
- #fetch_values(groupped_collection) ⇒ Object
- #group_by(type) ⇒ Object
-
#initialize ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize ⇒ Collection
Returns a new instance of Collection.
8 9 10 |
# File 'lib/railswatch/models/collection.rb', line 8 def initialize @data = [] end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/railswatch/models/collection.rb', line 6 def data @data end |
Instance Method Details
#add(record) ⇒ Object
12 13 14 |
# File 'lib/railswatch/models/collection.rb', line 12 def add(record) @data << record end |
#fetch_values(groupped_collection) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/railswatch/models/collection.rb', line 25 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
16 17 18 19 20 21 22 23 |
# File 'lib/railswatch/models/collection.rb', line 16 def group_by(type) case type when :controller_action, :controller_action_format, :datetime, :path fetch_values @data.group_by(&type) else {} end end |