Class: Pairity::CLI
- Inherits:
-
Object
- Object
- Pairity::CLI
- Defined in:
- lib/pairity/cli.rb
Instance Method Summary collapse
- #action_menu ⇒ Object
- #add_people ⇒ Object
- #all_combos ⇒ Object
- #change_channel ⇒ Object
- #change_tier ⇒ Object
- #choose_from_generated_pair ⇒ Object
- #choose_pair ⇒ Object
- #choose_person(tier: false) ⇒ Object
- #condemn_pair(pair) ⇒ Object
- #decrease_chance(pair) ⇒ Object
- #display_pair(rows, person1, person2) ⇒ Object
- #display_pair_names(pair) ⇒ Object
- #display_pair_stats ⇒ Object
- #display_pairs ⇒ Object
- #display_person(person, tier: false) ⇒ Object
- #edit_pair ⇒ Object
- #edit_people ⇒ Object
- #generate_pairs ⇒ Object
- #increase_chance(pair) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #load_google ⇒ Object
- #nope_pair ⇒ Object
- #open_google_sheet ⇒ Object
- #pairs_menu ⇒ Object
- #remove_people ⇒ Object
- #rename ⇒ Object
- #save_changes ⇒ Object
- #save_pairs ⇒ Object
- #simulate_pairs ⇒ Object
- #slack_config ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
8 9 10 11 12 13 14 |
# File 'lib/pairity/cli.rb', line 8 def initialize @matrix = AdjacencyMatrix.new @sync = GoogleSync.new(@matrix) @generator = PairGenerator.new(@matrix) @renderer = PairRenderer.new(@matrix) load_google end |
Instance Method Details
#action_menu ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pairity/cli.rb', line 24 def puts puts Rainbow("==== PAIRITY ====").white choose do || .prompt = "What would you like to do?" .choice("Generate Pairs") { generate_pairs } .choice("Edit People") { edit_people } # menu.choice("Edit Pair") { edit_pair } .choice("Save Changes") { save_changes } .choice("Open Google Sheet") { open_google_sheet } .choice("Change Slack Channel") { change_channel } end end |
#add_people ⇒ Object
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/pairity/cli.rb', line 150 def add_people names = ask "What are their names? (enter names separated by commas)" names = names.split(",") names.each do |name| person = Person.new(name: name.strip) @matrix.add_person(person) puts "Added #{name.strip}!" end end |
#all_combos ⇒ Object
298 299 300 |
# File 'lib/pairity/cli.rb', line 298 def all_combos @matrix.people.combination(2) end |
#change_channel ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pairity/cli.rb', line 57 def change_channel puts "Let's set up Slack Integration." Config.load channel = ask("What channel would you like to post to? (Don't write the #')") Config.add(channel: channel) Config.save puts "Channel changed to ##{channel}" end |
#change_tier ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/pairity/cli.rb', line 97 def change_tier choice = choose_person(tier: true) tier = 2 choose do || .prompt = "Set #{Rainbow(choice.name).white} to what tier?" .choice("Tier 1") { tier = 1 } .choice("Tier 2") { tier = 2 } .choice("Tier 3") { tier = 3 } end choice.tier = tier puts "#{Rainbow(choice.name).white} is now tier #{tier}." end |
#choose_from_generated_pair ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/pairity/cli.rb', line 178 def choose_from_generated_pair choice = nil choose do || .prompt = "Who would you like to edit?" @generator.pairs.each_with_index do |pair, index| .choice(display_pair_names(pair)) { choice = index } end end choice = @generator.pairs[choice] end |
#choose_pair ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/pairity/cli.rb', line 191 def choose_pair choice = nil choose do || .prompt = "Who would you like to edit?" all_combos.with_index do |pair, index| .choice(display_pair_names(pair)) { choice = index } end end choice = all_combos.to_a[choice] end |
#choose_person(tier: false) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/pairity/cli.rb', line 131 def choose_person(tier: false) people = @matrix.people(true) choice = nil choose do || .prompt = "Select a person." people.each_with_index do |person, index| .choice(display_person(person, tier: tier)) { choice = people[index] } end end choice end |
#condemn_pair(pair) ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/pairity/cli.rb', line 245 def condemn_pair(pair) answer = ask "Are you sure you would like to condemn #{display_pair_names(pair)}?" do |q| q.validate = /y|n/ end if answer =~ /y/ @generator.abolish_pairing(*pair) puts "#{display_pair_names(pair)} will no longer be paired." end end |
#decrease_chance(pair) ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/pairity/cli.rb', line 231 def decrease_chance(pair) answer = ask "Are you sure you would like to decrease the odds of #{display_pair_names(pair)} pairing?" do |q| q.validate = /y|n/ end if answer =~ /y/ p1, p2 = pair @generator.resistance(p1, p2, 2) puts "#{display_pair_names(pair)} are less likely to be paired." end end |
#display_pair(rows, person1, person2) ⇒ Object
325 326 327 328 329 330 |
# File 'lib/pairity/cli.rb', line 325 def display_pair(rows, person1, person2) cols = [] cols << display_pair_names([person1, person2]) cols << @renderer.stats_for_pair(person1, person2) rows << cols end |
#display_pair_names(pair) ⇒ Object
320 321 322 323 |
# File 'lib/pairity/cli.rb', line 320 def display_pair_names(pair) person1, person2 = pair Rainbow(person1).white + " & " + Rainbow(person2).white end |
#display_pair_stats ⇒ Object
302 303 304 305 306 307 308 309 |
# File 'lib/pairity/cli.rb', line 302 def display_pair_stats rows = [] all_combos.each do |person1, person2| display_pair(rows, person1, person2) end table = Terminal::Table.new headings: ["Pair","Times"], rows: rows puts table end |
#display_pairs ⇒ Object
311 312 313 314 315 316 317 318 |
# File 'lib/pairity/cli.rb', line 311 def display_pairs rows = [] @generator.pairs.each do |person1, person2| display_pair(rows, person1, person2) end table = Terminal::Table.new headings: ["Pair","Times"], rows: rows puts table end |
#display_person(person, tier: false) ⇒ Object
143 144 145 146 147 148 |
# File 'lib/pairity/cli.rb', line 143 def display_person(person, tier: false) output = [] output << "#{Rainbow(person.name).white}" output << "-- Tier #{person.tier}" if tier output.join(" ") end |
#edit_pair ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/pairity/cli.rb', line 205 def edit_pair choice = choose_pair choose do || .prompt = "How would you like to edit #{display_pair_names(choice)}" .choice("Increase Pair Chance") { increase_chance(choice) } .choice("Decrease Pair Chance") { decrease_chance(choice) } .choice("Abolish Pair Chance") { condemn_pair(choice) } end end |
#edit_people ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/pairity/cli.rb', line 69 def edit_people choose do || .prompt = "Add or remove?" .choice("Add") { add_people } .choice("Remove") { remove_people } .choice("Rename") { rename } .choice("Change Tier") { change_tier } end end |
#generate_pairs ⇒ Object
259 260 261 262 263 |
# File 'lib/pairity/cli.rb', line 259 def generate_pairs @generator.generate_pairs puts end |
#increase_chance(pair) ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/pairity/cli.rb', line 217 def increase_chance(pair) answer = ask "Are you sure you would like to increase the odds of #{display_pair_names(pair)} pairing?" do |q| q.validate = /y|n/ end if answer =~ /y/ p1, p2 = pair @generator.resistance(p1, p2, 0.5) puts "#{display_pair_names(pair)} are more likely to be paired." end end |
#load_google ⇒ Object
332 333 334 |
# File 'lib/pairity/cli.rb', line 332 def load_google @sync.load end |
#nope_pair ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/pairity/cli.rb', line 161 def nope_pair pair = choose_from_generated_pair answer = ask "Are you sure you would like to nope today's #{display_pair_names(pair)} pairing?" do |q| q.validate = /y|n/ end if answer =~ /y/ p1, p2 = pair @generator.nope(p1, p2) puts "#{display_pair_names(pair)} have been 'Noped'!" end @generator.generate_pairs end |
#open_google_sheet ⇒ Object
38 39 40 41 42 |
# File 'lib/pairity/cli.rb', line 38 def open_google_sheet `open "#{@sync.sheet_url}"` end |
#pairs_menu ⇒ Object
265 266 267 268 269 270 271 272 273 274 |
# File 'lib/pairity/cli.rb', line 265 def display_pairs puts choose do || .prompt = "What would you like to do?" .choice("Save & Slack") { save_pairs } .choice("'Nope' a Pair") { nope_pair } .choice("Main Menu") { } end end |
#remove_people ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/pairity/cli.rb', line 115 def remove_people choice = choose_person answer = ask "Are you sure you would like to remove #{Rainbow(choice).white}?" do |q| q.validate = /y|n/ end if answer =~ /y/ @matrix.remove_person(choice) end puts "#{Rainbow(choice).white} has been removed." end |
#rename ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/pairity/cli.rb', line 84 def rename choice = choose_person new_name = ask "What name would you like to give #{Rainbow(choice.name).white}?" old_name = choice.name choice.name = new_name puts "#{Rainbow(old_name).white} shall henceforth be known as #{Rainbow(choice.name).white}!" end |
#save_changes ⇒ Object
79 80 81 82 |
# File 'lib/pairity/cli.rb', line 79 def save_changes @sync.save end |
#save_pairs ⇒ Object
276 277 278 279 280 281 282 283 |
# File 'lib/pairity/cli.rb', line 276 def save_pairs @generator.save_pairs puts PairSaver.new(@generator.pairs).post_to_slack say "Posted pairings to slack!" @sync.save end |
#simulate_pairs ⇒ Object
285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/pairity/cli.rb', line 285 def simulate_pairs times = ask("How many days should we to travel?") times.to_i.times do @generator.generate_pairs @generator.save_pairs end display_pair_stats end |
#slack_config ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pairity/cli.rb', line 44 def slack_config puts "Let's set up Slack Integration." Config.load slack_webhook = ask("Please enter your Slack Webhook URL (more information: https://vikingcodeschool.slack.com/apps/new/A0F7XDUAZ-incoming-webhooks)") do |q| q.validate = /hooks\.slack\.com\/services\// end channel = ask("What channel would you like to post to? (Don't write the #')") Config.add(url: slack_webhook, channel: channel) Config.save end |
#start ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/pairity/cli.rb', line 16 def start unless Config.configured? slack_config end end |