Class: SeedList::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/seed_list/cli.rb

Instance Method Summary collapse

Instance Method Details

#edit(tournament_id) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/seed_list/cli.rb', line 8

def edit(tournament_id)
  @tournament_id = tournament_id
  trap_signals
  say "Using #{ENV['EDITOR']} (set $EDITOR to change)", :green
  say 'Loading environment...', :green
  say 'Exporting seed list...', :green

  old_list = players.map { |p| p. }

  new_list = editor "tournament-#{tournament.id}-edit-seeds" do
    buffer =  "# Seed list for \"#{tournament.title}\" (##{tournament.id})\n\n"
    buffer << "# Organize the players below by skill from best to worst.\n"
    buffer << "# Save and quit to replace the seed list for this tournament.\n\n"

    buffer << old_list.join("\n")
  end.split("\n")
  system('clear')

  if new_list == old_list
    say 'Nothing changed.', :yellow
  else
    say 'Seed list updated, saving...', :green
    replace_seed_list new_list
  end
end

#export(tournament_id) ⇒ Object



42
43
44
45
46
# File 'lib/seed_list/cli.rb', line 42

def export(tournament_id)
  @tournament_id = tournament_id
  trap_signals
  players.each { |p| puts p. }
end

#import(tournament_id) ⇒ Object



35
36
37
38
39
# File 'lib/seed_list/cli.rb', line 35

def import(tournament_id)
  @tournament_id = tournament_id
  trap_signals
  replace_seed_list STDIN.read.split("\n")
end