Class: Notifications
- Inherits:
-
Object
- Object
- Notifications
- Defined in:
- lib/models/notifications.rb
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(**options) ⇒ Notifications
constructor
A new instance of Notifications.
Constructor Details
#initialize(**options) ⇒ Notifications
Returns a new instance of Notifications.
15 16 17 18 19 20 |
# File 'lib/models/notifications.rb', line 15 def initialize(**) @dt = [:dt] @start_at = [:start_at] @finish_at = [:finish_at] @notifications = Rpush::Notification.all end |
Instance Method Details
#data ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/models/notifications.rb', line 22 def data fetch = -> a { a['delivered'] ? [true, a['delivered_at']] : [false, a['failed_at']] } @notifications.map(&:attributes) .map(&fetch) .select { |_,d| d.to_i >= @start_at.to_i && d.to_i <= @finish_at.to_i } .sort_by(&:last) .group_by { |_,d| (d.to_i - @start_at.to_i) / @dt.to_i } .map_value { |g| {true => 0, false => 0}.merge g.group_by(&:first).map_value(&:size) } end |