hlockey-cli 3 → 4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e525ff3f2707721f9bef74532f8ca4a3ea9fb9aa18708a13fc56d56f3ebc615
4
- data.tar.gz: ae05fa875ecd8b7ecd57d6a2d9256d69f6400286f5e9df66c52a656eeea68e66
3
+ metadata.gz: 20dbbe21705cef26f25805ff8ff5e00093b6cae75b631b5285a03524401b80a9
4
+ data.tar.gz: e7858da88ee692700c1a47dd2496ba9b533e3e9c69d86cbfa144ef9eb825455b
5
5
  SHA512:
6
- metadata.gz: 37b4cf715312b89b4a1e226f67ff240195847aa6d12483888d73248c9f148631ca057a7a87de2159a1f30fae4daac5d9977326d00a73c2b7c021b494ce4ea109
7
- data.tar.gz: 1588dcb597e6c17881107a38f0ab5cf26b37afe48a23c28fae90c63c30a2ba52bbd99ae9ee97208fd9151698ed805b272a1034b79f0aca1b2fe1cf7be949e792
6
+ metadata.gz: '09539eff948b07b8c1674f6ad55eac92eb388738bdc3db8fa936b08e122668e5fc22242c1d228f6b621013aca534547f94a991936dbd5443fa2f3af7f31cfc40'
7
+ data.tar.gz: c374e0f96b827d21ec6777fc168474b876aae83ea2e03ade519d7f105be3d0ca26e5cb81668ea49f469aa465dd2e6c9970cdb60a841e3152e8bd4064e9330ec9
@@ -19,13 +19,13 @@ module HlockeyCLI
19
19
 
20
20
  puts("#{chosen_game.home.emoji} #{chosen_game} #{chosen_game.away.emoji}")
21
21
 
22
+ stream_idx = 0
22
23
  loop do
23
24
  league.update_state
24
- chosen_game.stream.each { |message| puts("#{message}\n\n") }
25
-
25
+ chosen_game.stream[stream_idx..].each { |message| puts("#{message}\n\n") }
26
+ stream_idx = chosen_game.stream.length
26
27
  break unless chosen_game.in_progress
27
28
 
28
- chosen_game.stream.clear
29
29
  sleep(5)
30
30
  end
31
31
  end
@@ -34,34 +34,55 @@ module HlockeyCLI
34
34
  if league.champion_team
35
35
  puts(Hlockey::Message.SeasonChampion(league.champion_team))
36
36
  elsif league.playoff_teams
37
- put_standings("Playoffs", league.playoff_teams)
37
+ (league.playoff_teams.length / 2).times do |i|
38
+ put_standings("Playoff Matchup #{i + 1}",
39
+ [league.playoff_teams[i], league.playoff_teams[-i - 1]])
40
+ end
41
+ puts("_" * 31) # Separator from regular standings
38
42
  end
39
43
  league.divisions.each { |name, teams| put_standings(name, teams) }
40
44
  end
41
45
 
42
46
  def team_info(league)
43
- chosen_team = HlockeyCLI.user_selection(league.teams)
44
- return if chosen_team.nil?
45
-
46
- puts("#{chosen_team.emoji} #{chosen_team}")
47
- chosen_team.roster.each do |pos, player|
48
- puts(" #{Hlockey::Team.pos_name(pos)}:\n #{player}")
49
- player.stats.each do |stat, value|
50
- puts(" #{stat}: #{value.round(1)}")
47
+ chosen_team = HlockeyCLI.user_selection(league.teams, default: "All teams")
48
+
49
+ (chosen_team.nil? ? league.teams : [chosen_team]).each do |team|
50
+ puts("#{team.emoji} #{team}")
51
+ puts("\"#{team.motto}\"")
52
+ team.roster.each do |pos, player|
53
+ puts(" #{Hlockey::Team.pos_name(pos)}:\n #{player}")
54
+ put_stats(player)
55
+ end
56
+ puts(" Shadows:")
57
+ team.shadows.each do |player|
58
+ puts(" #{player}")
59
+ put_stats(player)
51
60
  end
61
+ puts(" Wins: #{team.wins}")
62
+ puts(" Losses: #{team.losses}")
52
63
  end
53
- puts(" wins: #{chosen_team.wins}")
54
- puts(" losses: #{chosen_team.losses}")
55
64
  end
56
65
 
57
- def election(_)
58
- Hlockey::Data.election.each do |category, options|
59
- puts(category)
60
- options.each { |name, description| puts(" #{name}\n #{description}") }
66
+ def election(league)
67
+ if league.start_time < Time.now
68
+ puts("Current election options\nGo to the website to vote.")
69
+ Hlockey::Data.election.each do |category, options|
70
+ puts(" #{category}")
71
+ options.each { |name, description| puts(" #{name}\n #{description}") }
72
+ end
73
+ end
74
+
75
+ election_results = Hlockey::Data.previous_election_results
76
+ puts("Previous election results\nvotes cast: #{election_results[:vote_amt]}")
77
+ election_results[:categories].each do |category, options|
78
+ puts(" #{category}")
79
+ options.each do |name, result|
80
+ puts(" #{name}\n #{result[:winner]}")
81
+ next if result[:most_votes].nil?
82
+
83
+ puts(" team with most votes: #{result[:most_votes]}")
84
+ end
61
85
  end
62
- # TODO: add an actual link to the website,
63
- # probably should be from Hlockey lib data
64
- puts("Go to the website to vote.")
65
86
  end
66
87
 
67
88
  def information(_)
@@ -77,7 +98,24 @@ module HlockeyCLI
77
98
 
78
99
  def put_standings(division_name, teams)
79
100
  puts(division_name)
80
- teams.each { |team| puts("#{team.emoji} #{team} ".ljust(27) + team.w_l) }
101
+ teams.each do |team|
102
+ status_emoji = case team.status
103
+ when :partying
104
+ " 🎉"
105
+ when :qualified
106
+ " ✅"
107
+ else
108
+ ""
109
+ end
110
+ puts("#{team.emoji} #{team}".ljust(27) + team.w_l + status_emoji)
111
+ end
112
+ end
113
+
114
+ # @param player [Hlockey::Player]
115
+ def put_stats(player)
116
+ player.stat_strings.each do |key, value|
117
+ puts(" #{key}: #{value}")
118
+ end
81
119
  end
82
120
  end
83
121
  end
@@ -1,5 +1,5 @@
1
1
  module HlockeyCLI
2
- def self.user_selection(choices, default: nil, str_process: proc { |s| s })
2
+ def self.user_selection(choices, default: "Back", str_process: ->(s) { s })
3
3
  puts("Please enter a number...")
4
4
 
5
5
  # 1 is added to i when printing choices
@@ -7,15 +7,11 @@ module HlockeyCLI
7
7
  choices.each_with_index do |choice, i|
8
8
  puts("#{(i + 1).to_s.rjust(2)} - #{str_process.call(choice)}")
9
9
  end
10
- puts("anything else - #{default || "Back"}")
10
+ puts("anything else - #{default}")
11
11
 
12
12
  # 1 is subracted to undo adding 1 earlier
13
13
  choice_idx = $stdin.gets.to_i - 1
14
14
 
15
- if !choice_idx.negative? && choice_idx < choices.length
16
- choices[choice_idx]
17
- else
18
- default
19
- end
15
+ !choice_idx.negative? && choice_idx < choices.length ? choices[choice_idx] : nil
20
16
  end
21
17
  end
@@ -1,3 +1,3 @@
1
1
  module HlockeyCLI
2
- VERSION = "3".freeze
2
+ VERSION = "4.1".freeze
3
3
  end
data/lib/hlockey-cli.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require("hlockey")
2
+ require("paint")
2
3
  require("hlockey-cli/actions")
3
4
  require("hlockey-cli/user_selection")
4
5
  require("hlockey-cli/version")
@@ -7,20 +8,30 @@ module HlockeyCLI
7
8
  def self.main
8
9
  puts("Please wait...")
9
10
 
11
+ Hlockey::Message.colorize = ->(color, string) { Paint[string, color] }
12
+
10
13
  league = Hlockey::League.new
14
+ alerts = league.alerts.clone
11
15
 
12
16
  puts(Hlockey::Message.SeasonStarts(league.start_time)) if Time.now < league.start_time
13
17
 
14
18
  loop do
15
19
  league.update_state
20
+
21
+ unless alerts == league.alerts
22
+ alerts = league.alerts.clone
23
+ alerts.each(&method(:puts))
24
+ puts # newline
25
+ end
16
26
  puts(Hlockey::Message.SeasonDay(league.day))
17
27
 
18
28
  selected_action = user_selection(
19
29
  Actions::ACTIONS,
20
- default: :Exit,
21
- str_process: proc { |s| s.to_s.capitalize.sub("_", " ") }
30
+ default: "Exit",
31
+ str_process: ->(s) { s.to_s.capitalize.sub("_", " ") }
22
32
  )
23
- exit if selected_action == :Exit
33
+ exit if selected_action.nil?
34
+
24
35
  Actions.send(selected_action, league)
25
36
  end
26
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hlockey-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: '3'
4
+ version: '4.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lavender Perry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-02 00:00:00.000000000 Z
11
+ date: 2023-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hlockey
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '3'
19
+ version: '4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: '3'
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: paint
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.3'
27
41
  description: Hlockey console application.
28
42
  email: endie2@protonmail.com
29
43
  executables: