Class: Hlockey::Team::Player
- Inherits:
-
Object
- Object
- Hlockey::Team::Player
- Defined in:
- lib/hlockey/team/player.rb
Overview
A player on a team
Instance Attribute Summary collapse
-
#mods ⇒ Object
Returns the value of attribute mods.
-
#name ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute name.
-
#stats ⇒ Object
Returns the value of attribute stats.
-
#team ⇒ Object
Returns the value of attribute team.
Instance Method Summary collapse
-
#initialize(name:, team:, stats:, mods: []) ⇒ Player
constructor
A new instance of Player.
-
#mods_do(action, *args) ⇒ Object
Calls a method on every mod this player has.
-
#stat_display ⇒ Hash<String => String>
#stats but better for displaying.
- #to_h(simple: false) ⇒ Hash
Constructor Details
#initialize(name:, team:, stats:, mods: []) ⇒ Player
Returns a new instance of Player.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hlockey/team/player.rb', line 18 def initialize(name:, team:, stats:, mods: []) @name = name @team = team @stats = stats @mods = mods.map do |mod| if mod.is_a?(Array) Mod::MODS.find { _1.to_s == "Hlockey::Mod::#{mod.first}" }.new(self, *mod[1..]) else Mod::MODS.find { _1.to_s == "Hlockey::Mod::#{mod}" }.new(self) end end end |
Instance Attribute Details
#mods ⇒ Object
Returns the value of attribute mods.
9 10 11 |
# File 'lib/hlockey/team/player.rb', line 9 def mods @mods end |
#name ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute name.
10 11 12 |
# File 'lib/hlockey/team/player.rb', line 10 def name @name end |
#stats ⇒ Object
Returns the value of attribute stats.
9 10 11 |
# File 'lib/hlockey/team/player.rb', line 9 def stats @stats end |
#team ⇒ Object
Returns the value of attribute team.
9 10 11 |
# File 'lib/hlockey/team/player.rb', line 9 def team @team end |
Instance Method Details
#mods_do(action, *args) ⇒ Object
Calls a method on every mod this player has
54 55 56 57 58 |
# File 'lib/hlockey/team/player.rb', line 54 def mods_do(action, *args) res = nil @mods.each { res ||= _1.send(action, *args) } res end |
#stat_display ⇒ Hash<String => String>
Returns #stats but better for displaying.
45 46 47 48 |
# File 'lib/hlockey/team/player.rb', line 45 def stat_display = Utils.hash_display_keys( @stats.transform_values { _1.round(2).to_s.ljust(4, "0") } ) |
#to_h(simple: false) ⇒ Hash
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/hlockey/team/player.rb', line 33 def to_h(simple: false) res = { name: @name, stats: @stats } res[:team] = @team.to_s unless simple res[:mods] = @mods.map(&:to_data) unless simple && @mods.empty? res end |