Class: LogfileInterval::AggregatorSet
- Inherits:
-
Object
- Object
- LogfileInterval::AggregatorSet
- Defined in:
- lib/logfile_interval/aggregator_set.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #add(record) ⇒ Object
-
#initialize(parser_columns) ⇒ AggregatorSet
constructor
A new instance of AggregatorSet.
- #to_hash ⇒ Object
Constructor Details
#initialize(parser_columns) ⇒ AggregatorSet
Returns a new instance of AggregatorSet.
3 4 5 6 7 8 9 10 |
# File 'lib/logfile_interval/aggregator_set.rb', line 3 def initialize(parser_columns) @parser_columns = parser_columns @aggregators = {} parser_columns.each do |name, | next unless klass = [:aggregator_class] @aggregators[name.to_sym] = klass.new(.fetch(:custom_options, {})) end end |
Instance Method Details
#[](name) ⇒ Object
24 25 26 27 |
# File 'lib/logfile_interval/aggregator_set.rb', line 24 def [](name) raise ArgumentError, "#{name} field does not exist" unless @aggregators.has_key?(name) @aggregators[name.to_sym].values end |
#add(record) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/logfile_interval/aggregator_set.rb', line 12 def add(record) @parser_columns.each do |name, | next unless @aggregators[name] if record.skip_with_exceptions? && (!.key?(:noskip) || [:noskip] == false) next end group_by_value = record[[:group_by]] if [:group_by] @aggregators[name].add(record[name], group_by_value) end end |
#to_hash ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/logfile_interval/aggregator_set.rb', line 29 def to_hash @aggregators.inject({}) do |h, pair| k = pair[0] v = pair[1] h[k] = v.values h end end |