class Notifications

Simple User Prompts

Public Class Methods

new() click to toggle source
# File lib/jiraquest/distractions/notifications.rb, line 7
def initialize
  @store = DATA
  @prompt = TTY::Prompt.new
  @notifications_list = %w[slack reddit text email]
end

Public Instance Methods

email() click to toggle source
# File lib/jiraquest/distractions/notifications.rb, line 29
def email
  @prompt.ok('Someone sent you an email')
end
list() click to toggle source
# File lib/jiraquest/distractions/notifications.rb, line 13
def list
  @notifications_list
end
random() click to toggle source
# File lib/jiraquest/distractions/notifications.rb, line 33
def random
  [slack, reddit, text, email].sample
end
read_notifications_count() click to toggle source
# File lib/jiraquest/distractions/notifications.rb, line 37
def read_notifications_count
  @store.transaction { @store['notifications'] }
end
reddit() click to toggle source
# File lib/jiraquest/distractions/notifications.rb, line 21
def reddit
  @prompt.ok('Someone replied to a Reddit post of yours')
end
slack() click to toggle source
# File lib/jiraquest/distractions/notifications.rb, line 17
def slack
  @prompt.ok('Someone sent you a slack message')
end
text() click to toggle source
# File lib/jiraquest/distractions/notifications.rb, line 25
def text
  @prompt.ok('Someone sent you a WhatsApp message')
end
update_warning(notification) click to toggle source
# File lib/jiraquest/distractions/notifications.rb, line 52
def update_warning(notification)
  @store.transaction { @store['warnings'][notification] += 1 }
end
warning() click to toggle source
# File lib/jiraquest/distractions/notifications.rb, line 41
def warning
  dc = read_notifications_count
  limits = dc.select { |_k, v| v > 2 }
  limits.each do |distraction, _count|
    @prompt.error("Be careful, you are spending a lot of time #{distraction}ing, "\
      'you may lose jiras!')
    update_warning(distraction)
  end
  false
end