Class: XiamiRadio::Notice

Inherits:
Object
  • Object
show all
Defined in:
lib/xiami_radio/notice.rb

Class Method Summary collapse

Class Method Details

.push(msg, expired = 3) ⇒ Object



5
6
7
# File 'lib/xiami_radio/notice.rb', line 5

def push(msg, expired = 3)
  queue << { content: msg, expired_at: Time.now.to_i + expired }
end

.queueObject



14
15
16
# File 'lib/xiami_radio/notice.rb', line 14

def queue
  @queue ||= []
end

.shiftObject



9
10
11
12
# File 'lib/xiami_radio/notice.rb', line 9

def shift
  queue.shift until queue.empty? || queue.first[:expired_at] > Time.now.to_i
  queue.first&.fetch(:content, nil)
end