Class: Rufio::NotificationManager
- Inherits:
-
Object
- Object
- Rufio::NotificationManager
- Defined in:
- lib/rufio/notification_manager.rb
Overview
Noice風の通知を管理するクラス画面右上に最大3個までの通知を表示
Constant Summary collapse
- MAX_NOTIFICATIONS =
3- DEFAULT_DISPLAY_DURATION =
秒
3
Instance Attribute Summary collapse
-
#notifications ⇒ Object
readonly
Returns the value of attribute notifications.
Instance Method Summary collapse
-
#add(name, type, duration:, exit_code: nil, display_duration: DEFAULT_DISPLAY_DURATION) ⇒ Object
通知を追加.
-
#clear ⇒ Object
全ての通知をクリア.
-
#count ⇒ Integer
通知の数.
-
#expire_old_notifications ⇒ Object
期限切れの通知を削除.
-
#initialize ⇒ NotificationManager
constructor
A new instance of NotificationManager.
Constructor Details
#initialize ⇒ NotificationManager
Returns a new instance of NotificationManager.
12 13 14 |
# File 'lib/rufio/notification_manager.rb', line 12 def initialize @notifications = [] end |
Instance Attribute Details
#notifications ⇒ Object (readonly)
Returns the value of attribute notifications.
10 11 12 |
# File 'lib/rufio/notification_manager.rb', line 10 def notifications @notifications end |
Instance Method Details
#add(name, type, duration:, exit_code: nil, display_duration: DEFAULT_DISPLAY_DURATION) ⇒ Object
通知を追加
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rufio/notification_manager.rb', line 22 def add(name, type, duration:, exit_code: nil, display_duration: DEFAULT_DISPLAY_DURATION) notification = { name: name, type: type, duration: duration, exit_code: exit_code, created_at: Time.now, display_duration: display_duration, border_color: type == :success ? :green : :red, status_text: build_status_text(type, duration) } @notifications << notification # 最大3個を超えた場合、最も古い通知を削除 @notifications.shift if @notifications.size > MAX_NOTIFICATIONS end |
#clear ⇒ Object
全ての通知をクリア
55 56 57 |
# File 'lib/rufio/notification_manager.rb', line 55 def clear @notifications.clear end |
#count ⇒ Integer
通知の数
50 51 52 |
# File 'lib/rufio/notification_manager.rb', line 50 def count @notifications.size end |
#expire_old_notifications ⇒ Object
期限切れの通知を削除
41 42 43 44 45 46 |
# File 'lib/rufio/notification_manager.rb', line 41 def expire_old_notifications now = Time.now @notifications.reject! do |notification| now - notification[:created_at] > notification[:display_duration] end end |