Sha256: 1da91b11c7814901d079a8fdc708f53decfec36ecb537bca04e2784892c6ff4f
Contents?: true
Size: 851 Bytes
Versions: 1
Compression:
Stored size: 851 Bytes
Contents
%w(table).each do |path| MetricFu.data_structures_require { path } end module MetricFu class Grouping def initialize(table, opts) column_name = opts.fetch(:by) order = opts.fetch(:order) { nil } hash = {} if column_name.to_sym == :metric # special optimized case hash = table.group_by_metric else table.each do |row| hash[row[column_name]] ||= Table.new(:column_names => row.attributes) hash[row[column_name]] << row end end if order @arr = hash.sort_by &order else @arr = hash.to_a end end def [](key) @arr.each do |group_key, table| return table if group_key == key end return nil end def each @arr.each do |value, rows| yield value, rows end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
metric_fu-2.1.3.4 | lib/data_structures/grouping.rb |