Class: Ruboty::Ragoon::Notification
- Inherits:
-
Object
- Object
- Ruboty::Ragoon::Notification
- Includes:
- NotifyOnce
- Defined in:
- lib/ruboty/ragoon/notification.rb
Defined Under Namespace
Classes: Item
Instance Attribute Summary collapse
-
#brain ⇒ Object
readonly
Returns the value of attribute brain.
-
#list ⇒ Object
readonly
Returns the value of attribute list.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(brain) ⇒ Notification
constructor
A new instance of Notification.
- #list_url ⇒ Object
- #retrieve ⇒ Object
- #unread_count ⇒ Object
Methods included from NotifyOnce
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
#brain ⇒ Object (readonly)
Returns the value of attribute brain.
6 7 8 |
# File 'lib/ruboty/ragoon/notification.rb', line 6 def brain @brain end |
#list ⇒ Object (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
28 29 30 |
# File 'lib/ruboty/ragoon/notification.rb', line 28 def empty? unread_count == 0 end |
#list_url ⇒ Object
32 33 34 |
# File 'lib/ruboty/ragoon/notification.rb', line 32 def list_url "#{@service.garoon_endpoint.gsub(/\?.*\Z/, '')}/notification/index" end |
#retrieve ⇒ Object
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_count ⇒ Object
24 25 26 |
# File 'lib/ruboty/ragoon/notification.rb', line 24 def unread_count @list.count end |