class Ruby::Pomodoro::Notification

Attributes

message[R]

Public Class Methods

new(message, channel) click to toggle source

@param message [String] Message @param channel [Object, Module] Channel to push message

# File lib/ruby/pomodoro/notification.rb, line 8
def initialize(message, channel)
  @message = message
  @channel = channel
end

Public Instance Methods

notify(repeat_at = nil, skip_now: false) click to toggle source

@param repeat_at [Numeric] Time to repeat @param skip_now [Boolean] Skip notify after call, default: false @return [TrueClass]

# File lib/ruby/pomodoro/notification.rb, line 16
def notify(repeat_at = nil, skip_now: false)
  @channel.call(message) unless skip_now
  repeat(repeat_at) if repeat_at
  true
end
stop() click to toggle source

@return [TrueClass]

# File lib/ruby/pomodoro/notification.rb, line 23
def stop
  @thread&.kill
  true
end

Private Instance Methods

repeat(time_at) click to toggle source
# File lib/ruby/pomodoro/notification.rb, line 30
def repeat(time_at)
  @thread = Thread.new do
    loop do
      sleep time_at
      @channel.call(message)
    end
  end
end