Module: HlockeyCLI::Actions

Defined in:
lib/hlockey-cli/actions.rb

Overview

Each action the CLI can do

Constant Summary collapse

ACTIONS =
%i[games standings team_info election information].freeze

Class Method Summary collapse

Class Method Details

.election(league) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/hlockey-cli/actions.rb', line 81

def election(league)
  if league.start_time < Time.now
    puts("Current election options\nGo to the website to vote.")
    Hlockey::Data.election.each do |category, options|
      puts("  #{category}")
      options.each { |name, description| puts("    #{name}\n      #{description}") }
    end
  end

  election_results = Hlockey::Data.previous_election_results
  puts("Previous election results\nvotes cast: #{election_results[:vote_amt]}")
  election_results[:categories].each do |category, options|
    puts("  #{category}")
    options.each do |name, result|
      puts("    #{name}\n      #{result[:winner]}")
      next if result[:most_votes].nil?

      puts("      team with most votes: #{result[:most_votes]}")
    end
  end
end

.games(league) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/hlockey-cli/actions.rb', line 10

def games(league)
  if league.games.empty?
    puts(Hlockey::Message.new(:season_off))
    return
  end

  chosen_game = HlockeyCLI.user_selection(
    league.games,
    str_process: proc do |game|
      <<~GAME
        #{game}
             Weather: #{game.weather}
             Stadium: #{Hlockey::Message.color(game.stadium)}
      GAME
    end
  )
  return if chosen_game.nil?

  puts("#{chosen_game.home.emoji} #{chosen_game} #{chosen_game.away.emoji}")

  stream_idx = 0
  loop do
    league.update_state
    chosen_game.stream[stream_idx..].each { |message| puts("#{message}\n\n") }
    stream_idx = chosen_game.stream.length
    break unless chosen_game.in_progress

    sleep(5)
  end
end

.information(_) ⇒ Object



103
104
105
106
107
108
109
110
# File 'lib/hlockey-cli/actions.rb', line 103

def information(_)
  Hlockey::Data.information.each do |title, info|
    puts(title)
    info.each_line { |line| puts("  #{line}") }
  end
  puts("Links")
  Hlockey::Data.links.each { |site, link| puts("  #{site}: #{link}") }
end

.standings(league) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/hlockey-cli/actions.rb', line 41

def standings(league)
  if league.champion_team
    puts(Hlockey::Message.new(:season_champion,
                              season: league.season,
                              team: league.champion_team))
  elsif league.playoff_teams
    (league.playoff_teams.length / 2).times do |i|
      put_standings("Playoff Matchup #{i + 1}",
                    [league.playoff_teams[i], league.playoff_teams[-i - 1]])
    end
    puts("_" * 31) # Separator from regular standings
  end
  league.divisions.each { |name, teams| put_standings(name, teams) }
end

.team_info(league) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/hlockey-cli/actions.rb', line 56

def team_info(league)
  chosen_team = HlockeyCLI.user_selection(league.teams, default: "All teams")

  (chosen_team.nil? ? league.teams : [chosen_team]).each do |team|
    puts("#{team.emoji} #{team}")
    puts("\"#{team.motto}\"")
    puts("  Evolutions: #{team.evolutions}")
    puts("  Stadium:")
    Hlockey::Utils.hash_display_keys(team.stadium.to_h).each do |key, val|
      puts("    #{key}: #{val}")
    end
    team.roster_display.each do |pos, player|
      puts("  #{pos}:\n    #{player}")
      put_info(player)
    end
    puts("  Shadows:")
    team.shadows.each do |player|
      puts("    #{player}")
      put_info(player)
    end
    puts("  Wins: #{team.wins}")
    puts("  Losses: #{team.losses}")
  end
end