class Activity

Workspace setup miniquest

Public Class Methods

new() click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 8
def initialize
  @store = DATA
  @prompt = TTY::Prompt.new
  @distractions_list = %w[water coffee walk text think complain chat tune]
end

Public Instance Methods

activities() click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/jiraquest/distractions/activities.rb, line 81
def activities
  @mode = @prompt.select('Do something else') do |menu|
    menu.default 1
    menu.choice name: 'Make coffee', value: 1
    menu.choice name: 'Have a chat', value: 2
    menu.choice name: 'Send a text', value: 3
    menu.choice name: 'Drink some water', value: 4
    menu.choice name: 'Complain', value: 5
    menu.choice name: 'Go for a walk', value: 6
    menu.choice name: 'Think', value: 7
    menu.choice name: 'Play some tunes', value: 8
  end
  @mode
end
boot_warning() click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 138
def boot_warning
  distract_warning('without even turning on your machine!')
end
chat() click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 31
def chat
  puts 'You chatted with your colleagues'
  update_distraction('chat')
end
choose() click to toggle source

rubocop:disable Metrics/CyclomaticComplexity

# File lib/jiraquest/distractions/activities.rb, line 97
def choose
  @distraction = case activities
                 when 1 then coffee
                 when 2 then chat
                 when 3 then text
                 when 4 then water
                 when 5 then complain
                 when 6 then walk
                 when 7 then think
                 when 8 then tune
                 end

  @distraction
end
coffee() click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 26
def coffee
  puts 'You made a coffee'
  update_distraction('coffee')
end
coffee_armageddon() click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 151
def coffee_armageddon
  dc = read_warnings_count
  limits = dc.select { |_k, v| v > 1 }
  limits.each do |distraction, _count|
    @prompt.error('You were warned! You now lose TEN jiras!')
    update_warning(distraction)
    Score.new.update_points(-10)
  end
  true
end
complain() click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 46
def complain
  puts 'You complained loudly'
  update_distraction('complain')
end
distract_count(distraction) click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 118
def distract_count(distraction)
  @store['distractions'][distraction]
end
distract_warning(message) click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 142
def distract_warning(message)
  dc = read_distractions_count
  limits = dc.select { |_k, v| v > 4 }
  limits.each do |distraction, count|
    @prompt.error("Be careful, you have had #{count} #{distraction}s " + message)
    update_warning(distraction)
  end
end
list() click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 14
def list
  @distractions_list
end
play_tune(*lines) click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 73
def play_tune(*lines)
  lines.each do |line|
    puts "🎶 #{line} 🎶"
    sleep(1)
  end
end
read_distractions_count() click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 18
def read_distractions_count
  @store.transaction { @store['distractions'] }
end
read_warnings_count() click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 22
def read_warnings_count
  @store.transaction { @store['warnings'] }
end
text() click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 36
def text
  puts 'You sent a text to your significant other'
  update_distraction('text')
end
think() click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 56
def think
  puts 'You thought about things'
  update_distraction('think')
end
tune() click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 61
def tune
  dc = read_distractions_count
  music = dc.select { |k, _v| k == 'tune' }
  played = music['tune']
  if played.even?
    play_tune('why', 'does your love', 'hurt so much')
  else
    play_tune('words', 'don\'t come easy', 'to me')
  end
  update_distraction('tune')
end
update_distraction(distraction) click to toggle source

rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/MethodLength

# File lib/jiraquest/distractions/activities.rb, line 114
def update_distraction(distraction)
  @store.transaction { @store['distractions'][distraction] += 1 }
end
update_warning(distraction) click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 126
def update_warning(distraction)
  @store.transaction { @store['warnings'][distraction] += 1 }
end
walk() click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 51
def walk
  puts 'You take a walk outside'
  update_distraction('walk')
end
warning() click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 130
def warning
  if coffee_armageddon
    complain
  else
    distract_warning('already, you may lose a jira!')
  end
end
warning_count(distraction) click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 122
def warning_count(distraction)
  @store['warnings'][distraction]
end
water() click to toggle source
# File lib/jiraquest/distractions/activities.rb, line 41
def water
  puts 'You drank some cucumber water'
  update_distraction('water')
end