Class: SC2Cli::Subcommands::LadderShared::LadderDetailsTeam

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

Constant Summary collapse

@@console =
Shared::Console.instance
@@colour_wins =
40
@@colour_losses =
160

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json:) ⇒ LadderDetailsTeam

Returns a new instance of LadderDetailsTeam.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/sc2cli/subcommands/ladder/ladderdetailsteam.rb', line 38

def initialize(json:)
  joined   = 0
  losses   = 0
  members  = Array.new
  mmr      = 0
  points   = 0
  previous = 0
  wins     = 0

  if json.key?("joinTimestamp") then
    joined = json["joinTimestamp"] if json["joinTimestamp"].kind_of?(Integer)
  end

  if json.key?("losses") then
    losses = json["losses"] if json["losses"].kind_of?(Integer)
  end

  if json.key?("teamMembers") then
    members = json["teamMembers"] if json["teamMembers"].kind_of?(Array)
  end

  if json.key?("mmr") then
    mmr = json["mmr"] if json["mmr"].kind_of?(Integer)
  end

  if json.key?("points") then
    points = json["points"] if json["points"].kind_of?(Integer)
  end

  if json.key?("previousRank") then
    previous = json["previousRank"] if json["previousRank"].kind_of?(Integer)
  end

  if json.key?("wins") then
    wins = json["wins"] if json["wins"].kind_of?(Integer)
  end

  @members  = LadderDetailsTeamMembers.new(json: members)
  @joined   = Time.at(joined)

  @losses   = losses
  @mmr      = mmr
  @points   = points
  @previous = previous
  @wins     = wins
end

Instance Attribute Details

#joinedObject (readonly)

Returns the value of attribute joined.



28
29
30
# File 'lib/sc2cli/subcommands/ladder/ladderdetailsteam.rb', line 28

def joined
  @joined
end

#lossesObject (readonly)

Returns the value of attribute losses.



29
30
31
# File 'lib/sc2cli/subcommands/ladder/ladderdetailsteam.rb', line 29

def losses
  @losses
end

#membersObject (readonly)

Returns the value of attribute members.



30
31
32
# File 'lib/sc2cli/subcommands/ladder/ladderdetailsteam.rb', line 30

def members
  @members
end

#mmrObject (readonly)

Returns the value of attribute mmr.



31
32
33
# File 'lib/sc2cli/subcommands/ladder/ladderdetailsteam.rb', line 31

def mmr
  @mmr
end

#pointsObject (readonly)

Returns the value of attribute points.



32
33
34
# File 'lib/sc2cli/subcommands/ladder/ladderdetailsteam.rb', line 32

def points
  @points
end

#previousObject (readonly)

Returns the value of attribute previous.



33
34
35
# File 'lib/sc2cli/subcommands/ladder/ladderdetailsteam.rb', line 33

def previous
  @previous
end

#winsObject (readonly)

Returns the value of attribute wins.



34
35
36
# File 'lib/sc2cli/subcommands/ladder/ladderdetailsteam.rb', line 34

def wins
  @wins
end

Instance Method Details

#to_sObject



87
88
89
90
91
92
93
94
95
96
# File 'lib/sc2cli/subcommands/ladder/ladderdetailsteam.rb', line 87

def to_s
  result = String.new

  joined = @joined.strftime("%Y-%m-%d %H:%M:%S")

  result += @members.to_s
  result += "MMR: #{@mmr.to_s}, Points: #{@points.to_s}, Wins: #{@@console.format(colour: @@colour_wins, message: @wins.to_s)}, Losses: #{@@console.format(colour: @@colour_losses, message: @losses.to_s)}, Joined: #{joined}\n\n"

  return result
end