Class: Ruboty::Ragoon::Notification

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

Defined Under Namespace

Classes: Item

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from NotifyOnce

#brain_key, #not_notified_ids

Constructor Details

#initialize(brain) ⇒ Notification

Returns a new instance of Notification.



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

def initialize(brain)
  @brain   = brain
  @service = ::Ragoon::Services::Notification.new
end

Instance Attribute Details

#brainObject (readonly)

Returns the value of attribute brain.



6
7
8
# File 'lib/ruboty/ragoon/notification.rb', line 6

def brain
  @brain
end

#listObject (readonly)

Returns the value of attribute list.



6
7
8
# File 'lib/ruboty/ragoon/notification.rb', line 6

def list
  @list
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/ruboty/ragoon/notification.rb', line 28

def empty?
  unread_count == 0
end

#list_urlObject



32
33
34
# File 'lib/ruboty/ragoon/notification.rb', line 32

def list_url
  "#{@service.garoon_endpoint.gsub(/\?.*\Z/, '')}/notification/index"
end

#retrieveObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/ruboty/ragoon/notification.rb', line 13

def retrieve
  new_notifications = @service.retrieve
                      .map { |data| Item.new(data) }
                      .find_all { |item| item.unread }

  new_notification_ids = new_notifications.map(&:id)
  ids_to_notify = not_notified_ids(new_notification_ids)

  @list = new_notifications.find_all { |n| ids_to_notify.include?(n.id) }
end

#unread_countObject



24
25
26
# File 'lib/ruboty/ragoon/notification.rb', line 24

def unread_count
  @list.count
end