Class: Activity
- Inherits:
-
Object
- Object
- Activity
- Defined in:
- lib/jiraquest/distractions/activities.rb
Overview
Workspace setup miniquest
Instance Method Summary collapse
-
#activities ⇒ Object
rubocop:disable Metrics/MethodLength.
- #boot_warning ⇒ Object
- #chat ⇒ Object
-
#choose ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
- #coffee ⇒ Object
- #coffee_armageddon ⇒ Object
- #complain ⇒ Object
- #distract_count(distraction) ⇒ Object
- #distract_warning(message) ⇒ Object
-
#initialize ⇒ Activity
constructor
A new instance of Activity.
- #list ⇒ Object
- #play_tune(*lines) ⇒ Object
- #read_distractions_count ⇒ Object
- #read_warnings_count ⇒ Object
- #text ⇒ Object
- #think ⇒ Object
- #tune ⇒ Object
-
#update_distraction(distraction) ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/MethodLength.
- #update_warning(distraction) ⇒ Object
- #walk ⇒ Object
- #warning ⇒ Object
- #warning_count(distraction) ⇒ Object
- #water ⇒ Object
Constructor Details
Instance Method Details
#activities ⇒ Object
rubocop:disable Metrics/MethodLength
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/jiraquest/distractions/activities.rb', line 81 def activities @mode = @prompt.select('Do something else') do || .default 1 .choice name: 'Make coffee', value: 1 .choice name: 'Have a chat', value: 2 .choice name: 'Send a text', value: 3 .choice name: 'Drink some water', value: 4 .choice name: 'Complain', value: 5 .choice name: 'Go for a walk', value: 6 .choice name: 'Think', value: 7 .choice name: 'Play some tunes', value: 8 end @mode end |
#boot_warning ⇒ Object
138 139 140 |
# File 'lib/jiraquest/distractions/activities.rb', line 138 def boot_warning distract_warning('without even turning on your machine!') end |
#chat ⇒ Object
31 32 33 34 |
# File 'lib/jiraquest/distractions/activities.rb', line 31 def chat puts 'You chatted with your colleagues' update_distraction('chat') end |
#choose ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# 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 ⇒ Object
26 27 28 29 |
# File 'lib/jiraquest/distractions/activities.rb', line 26 def coffee puts 'You made a coffee' update_distraction('coffee') end |
#coffee_armageddon ⇒ Object
151 152 153 154 155 156 157 158 159 160 |
# 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 ⇒ Object
46 47 48 49 |
# File 'lib/jiraquest/distractions/activities.rb', line 46 def complain puts 'You complained loudly' update_distraction('complain') end |
#distract_count(distraction) ⇒ Object
118 119 120 |
# File 'lib/jiraquest/distractions/activities.rb', line 118 def distract_count(distraction) @store['distractions'][distraction] end |
#distract_warning(message) ⇒ Object
142 143 144 145 146 147 148 149 |
# File 'lib/jiraquest/distractions/activities.rb', line 142 def distract_warning() 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 " + ) update_warning(distraction) end end |
#list ⇒ Object
14 15 16 |
# File 'lib/jiraquest/distractions/activities.rb', line 14 def list @distractions_list end |
#play_tune(*lines) ⇒ Object
73 74 75 76 77 78 |
# 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 ⇒ Object
18 19 20 |
# File 'lib/jiraquest/distractions/activities.rb', line 18 def read_distractions_count @store.transaction { @store['distractions'] } end |
#read_warnings_count ⇒ Object
22 23 24 |
# File 'lib/jiraquest/distractions/activities.rb', line 22 def read_warnings_count @store.transaction { @store['warnings'] } end |
#text ⇒ Object
36 37 38 39 |
# File 'lib/jiraquest/distractions/activities.rb', line 36 def text puts 'You sent a text to your significant other' update_distraction('text') end |
#think ⇒ Object
56 57 58 59 |
# File 'lib/jiraquest/distractions/activities.rb', line 56 def think puts 'You thought about things' update_distraction('think') end |
#tune ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# 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) ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/MethodLength
114 115 116 |
# File 'lib/jiraquest/distractions/activities.rb', line 114 def update_distraction(distraction) @store.transaction { @store['distractions'][distraction] += 1 } end |
#update_warning(distraction) ⇒ Object
126 127 128 |
# File 'lib/jiraquest/distractions/activities.rb', line 126 def update_warning(distraction) @store.transaction { @store['warnings'][distraction] += 1 } end |
#walk ⇒ Object
51 52 53 54 |
# File 'lib/jiraquest/distractions/activities.rb', line 51 def walk puts 'You take a walk outside' update_distraction('walk') end |
#warning ⇒ Object
130 131 132 133 134 135 136 |
# 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) ⇒ Object
122 123 124 |
# File 'lib/jiraquest/distractions/activities.rb', line 122 def warning_count(distraction) @store['warnings'][distraction] end |
#water ⇒ Object
41 42 43 44 |
# File 'lib/jiraquest/distractions/activities.rb', line 41 def water puts 'You drank some cucumber water' update_distraction('water') end |