Class: SC2Cli::Subcommands::LadderShared::LadderDetailsTeams

Inherits:
Object
  • Object
show all
Defined in:
lib/sc2cli/subcommands/ladder/ladderdetailsteams.rb

Instance Method Summary collapse

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

#countObject



41
42
43
# File 'lib/sc2cli/subcommands/ladder/ladderdetailsteams.rb', line 41

def count
  return @teams.length
end

#to_sObject



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