Class: SC2Cli::Subcommands::LadderShared::LadderDetailsTeams
- Inherits:
-
Object
- Object
- SC2Cli::Subcommands::LadderShared::LadderDetailsTeams
- Defined in:
- lib/sc2cli/subcommands/ladder/ladderdetailsteams.rb
Instance Method Summary collapse
- #add(team:) ⇒ Object
- #count ⇒ Object
-
#initialize(json:) ⇒ LadderDetailsTeams
constructor
A new instance of LadderDetailsTeams.
- #to_s ⇒ Object
- #with_member(player:) ⇒ Object
Constructor Details
#initialize(json:) ⇒ LadderDetailsTeams
Returns a new instance of LadderDetailsTeams.
23 24 25 26 27 28 29 30 |
# File 'lib/sc2cli/subcommands/ladder/ladderdetailsteams.rb', line 23 def initialize(json:) @teams = Array.new json.each do |team| team = LadderDetailsTeam.new(json: team) add(team: team) end end |
Instance Method Details
#add(team:) ⇒ Object
34 35 36 37 |
# File 'lib/sc2cli/subcommands/ladder/ladderdetailsteams.rb', line 34 def add(team:) @teams << team if team.kind_of?(LadderDetailsTeam) @teams.sort_by!{ |team| team.points } end |
#count ⇒ Object
41 42 43 |
# File 'lib/sc2cli/subcommands/ladder/ladderdetailsteams.rb', line 41 def count return @teams.length end |
#to_s ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/sc2cli/subcommands/ladder/ladderdetailsteams.rb', line 47 def to_s result = String.new @teams.each do |team| result += team.to_s end return result end |
#with_member(player:) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/sc2cli/subcommands/ladder/ladderdetailsteams.rb', line 59 def with_member(player:) result = LadderDetailsTeams.new(json: Array.new) @teams.each do |team| result.add(team: team) if team.members.has_player(player: player) end return result end |