Class: Ruboty::Ragoon::Remind

Inherits:
Object
  • Object
show all
Includes:
NotifyOnce
Defined in:
lib/ruboty/ragoon/remind.rb

Constant Summary collapse

NOTIFY_BEFORE_EVENT_START =

minutes before start_at

3

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from NotifyOnce

#brain_key, #not_notified_ids

Constructor Details

#initialize(brain) ⇒ Remind

Returns a new instance of Remind.



9
10
11
# File 'lib/ruboty/ragoon/remind.rb', line 9

def initialize(brain)
  @brain = brain
end

Instance Attribute Details

#brainObject (readonly)

Returns the value of attribute brain.



5
6
7
# File 'lib/ruboty/ragoon/remind.rb', line 5

def brain
  @brain
end

#eventObject (readonly)

Returns the value of attribute event.



5
6
7
# File 'lib/ruboty/ragoon/remind.rb', line 5

def event
  @event
end

Instance Method Details

#retrieveObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ruboty/ragoon/remind.rb', line 13

def retrieve
  now = Time.now.localtime

  @event = Event.new
  @event.filter_events do |event|
    begin
      event_start = Time.parse(event[:start_at]).localtime
      event_start.between?(now, now + NOTIFY_BEFORE_EVENT_START * 60)
    rescue
      false
    end
  end

  new_event_ids = not_notified_ids(@event.events.map { |event| event[:id] })
  @event.filter_events do |event|
    new_event_ids.include?(event[:id])
  end

  @event
end