Class: Hlockey::Team
- Inherits:
-
Object
- Object
- Hlockey::Team
- Defined in:
- lib/hlockey/team.rb,
lib/hlockey/team/player.rb,
lib/hlockey/team/stadium.rb
Overview
A team in the league Created by League when data is loaded
Defined Under Namespace
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#emoji ⇒ Object
readonly
Returns the value of attribute emoji.
-
#evolutions ⇒ Object
readonly
Returns the value of attribute evolutions.
-
#losses ⇒ Object
Returns the value of attribute losses.
-
#motto ⇒ Object
readonly
Returns the value of attribute motto.
-
#name ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute name.
-
#roster ⇒ Object
Returns the value of attribute roster.
-
#shadows ⇒ Object
Returns the value of attribute shadows.
-
#stadium ⇒ Object
readonly
Returns the value of attribute stadium.
-
#status ⇒ Object
Returns the value of attribute status.
-
#wins ⇒ Object
Returns the value of attribute wins.
Class Method Summary collapse
-
.pos_name(pos) ⇒ Object
Takes symbol from Team roster & converts it to full position name.
Instance Method Summary collapse
-
#initialize(name:, color:, emoji:, motto:, stadium:, roster:, shadows:, evolutions: 0) ⇒ Team
constructor
A new instance of Team.
- #players ⇒ Array<Player>
- #positive_record? ⇒ Boolean
-
#roster_display ⇒ Hash<String => Player>
#roster, but with keys better for displaying.
- #to_h(simple: false) ⇒ Hash
-
#w_l ⇒ String
Wins/losses in string representation.
-
#worst_player_pos ⇒ Symbol
The position of the worst player on the roster.
Constructor Details
#initialize(name:, color:, emoji:, motto:, stadium:, roster:, shadows:, evolutions: 0) ⇒ Team
Returns a new instance of Team.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hlockey/team.rb', line 21 def initialize(name:, color:, emoji:, motto:, stadium:, roster:, shadows:, evolutions: 0) @name = name @color = color @emoji = emoji @motto = motto @evolutions = evolutions @stadium = Stadium.new(team: self, **stadium) @roster = roster.transform_values { Player.new(**_1, team: self) } @shadows = shadows.map { Player.new(**_1, team: self) } @status = :in_contention @wins = @losses = 0 end |
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color.
10 11 12 |
# File 'lib/hlockey/team.rb', line 10 def color @color end |
#emoji ⇒ Object (readonly)
Returns the value of attribute emoji.
10 11 12 |
# File 'lib/hlockey/team.rb', line 10 def emoji @emoji end |
#evolutions ⇒ Object (readonly)
Returns the value of attribute evolutions.
10 11 12 |
# File 'lib/hlockey/team.rb', line 10 def evolutions @evolutions end |
#losses ⇒ Object
Returns the value of attribute losses.
9 10 11 |
# File 'lib/hlockey/team.rb', line 9 def losses @losses end |
#motto ⇒ Object (readonly)
Returns the value of attribute motto.
10 11 12 |
# File 'lib/hlockey/team.rb', line 10 def motto @motto end |
#name ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute name.
10 11 12 |
# File 'lib/hlockey/team.rb', line 10 def name @name end |
#roster ⇒ Object
Returns the value of attribute roster.
9 10 11 |
# File 'lib/hlockey/team.rb', line 9 def roster @roster end |
#shadows ⇒ Object
Returns the value of attribute shadows.
9 10 11 |
# File 'lib/hlockey/team.rb', line 9 def shadows @shadows end |
#stadium ⇒ Object (readonly)
Returns the value of attribute stadium.
10 11 12 |
# File 'lib/hlockey/team.rb', line 10 def stadium @stadium end |
#status ⇒ Object
Returns the value of attribute status.
9 10 11 |
# File 'lib/hlockey/team.rb', line 9 def status @status end |
#wins ⇒ Object
Returns the value of attribute wins.
9 10 11 |
# File 'lib/hlockey/team.rb', line 9 def wins @wins end |
Class Method Details
.pos_name(pos) ⇒ Object
Takes symbol from Team roster & converts it to full position name
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/hlockey/team.rb', line 79 def self.pos_name(pos) = case pos when :lwing "Left wing" when :rwing "Right wing" when :ldef "Left defender" when :rdef "Right defender" else pos.capitalize.to_s end |
Instance Method Details
#players ⇒ Array<Player>
69 |
# File 'lib/hlockey/team.rb', line 69 def players = @roster.values + @shadows |
#positive_record? ⇒ Boolean
66 |
# File 'lib/hlockey/team.rb', line 66 def positive_record? = @wins > @losses |
#roster_display ⇒ Hash<String => Player>
Returns #roster, but with keys better for displaying.
76 |
# File 'lib/hlockey/team.rb', line 76 def roster_display = @roster.transform_keys(&self.class.method(:pos_name)) |
#to_h(simple: false) ⇒ Hash
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/hlockey/team.rb', line 39 def to_h(simple: false) res = { name: @name, color: @color, emoji: @emoji, motto: @motto, evolutions: @evolutions, stadium: @stadium.to_h(simple:), roster: @roster.transform_values { _1.to_h(simple:) }, shadows: @shadows.map { _1.to_h(simple:) } } res.delete(:evolutions) if simple && res[:evolutions].zero? unless simple res[:status] = @status res[:wins] = @wins res[:losses] = @losses end res end |
#w_l ⇒ String
Returns wins/losses in string representation.
63 |
# File 'lib/hlockey/team.rb', line 63 def w_l = "#{@wins}-#{@losses}" |
#worst_player_pos ⇒ Symbol
Returns the position of the worst player on the roster.
72 73 |
# File 'lib/hlockey/team.rb', line 72 def worst_player_pos = @roster.transform_values { |v| v.stats.values.sum }.min_by { |_, v| v }.first |