Class: Groupdate::Magic::Enumerable

Inherits:
Groupdate::Magic show all
Defined in:
lib/groupdate/magic.rb

Constant Summary

Constants inherited from Groupdate::Magic

DAYS

Instance Attribute Summary

Attributes inherited from Groupdate::Magic

#group_index, #options, #period

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Groupdate::Magic

#day_start, #initialize, #series_builder, #series_label, #time_range, #time_zone, #validate_arguments, #validate_keywords, validate_period, #week_start

Constructor Details

This class inherits a constructor from Groupdate::Magic

Class Method Details

.group_by(enum, period, options, &block) ⇒ Object



96
97
98
# File 'lib/groupdate/magic.rb', line 96

def self.group_by(enum, period, options, &block)
  Groupdate::Magic::Enumerable.new(period: period, **options).group_by(enum, &block)
end

Instance Method Details

#group_by(enum, &_block) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/groupdate/magic.rb', line 87

def group_by(enum, &_block)
  group = enum.group_by do |v|
    v = yield(v)
    raise ArgumentError, "Not a time" unless v.respond_to?(:to_time)
    series_builder.round_time(v)
  end
  series_builder.generate(group, default_value: [], series_default: false)
end