Class: SC2Cli::Subcommands::LeagueShared::LeagueTier

Inherits:
Object
  • Object
show all
Defined in:
lib/sc2cli/subcommands/league/leaguetier.rb

Constant Summary collapse

@@console =
Shared::Console.instance
@@mmr_min =
0
@@mmr_max =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(league:, colour:, json:) ⇒ LeagueTier

Returns a new instance of LeagueTier.



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
# File 'lib/sc2cli/subcommands/league/leaguetier.rb', line 40

def initialize(league:, colour:, json:)
  @@console.fatal("Returned league information for: #{league} has a tier with a missing ID!") unless json.key?("id")

  id = json["id"]

  @@console.fatal("Returned league information for: #{league} has a tier with an ID that is not an integer!") unless id.kind_of?(Integer)
  @@console.fatal("Returned league information for: #{league} has a tier with an ID that is invalid!") unless id >= 0

  @id     = id
  @league = league
  @number = id + 1
  @colour = colour

  if json.key?("min_rating") then
    mmr_min = json["min_rating"]
    @mmr_min = mmr_min if mmr_min.kind_of?(Integer)
  end

  if json.key?("max_rating") then
    mmr_max = json["max_rating"]
    @mmr_max = mmr_max if mmr_max.kind_of?(Integer)
  end

  @mmr_min ||= @@mmr_min
  @mmr_max ||= @@mmr_max
end

Instance Attribute Details

#colourObject (readonly)

Returns the value of attribute colour.



33
34
35
# File 'lib/sc2cli/subcommands/league/leaguetier.rb', line 33

def colour
  @colour
end

#idObject (readonly)

Returns the value of attribute id.



34
35
36
# File 'lib/sc2cli/subcommands/league/leaguetier.rb', line 34

def id
  @id
end

#leagueObject (readonly)

Returns the value of attribute league.



35
36
37
# File 'lib/sc2cli/subcommands/league/leaguetier.rb', line 35

def league
  @league
end

#numberObject (readonly)

Returns the value of attribute number.



36
37
38
# File 'lib/sc2cli/subcommands/league/leaguetier.rb', line 36

def number
  @number
end

Instance Method Details

#lowerObject



69
70
71
# File 'lib/sc2cli/subcommands/league/leaguetier.rb', line 69

def lower
  return @mmr_min
end

#to_sObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/sc2cli/subcommands/league/leaguetier.rb', line 81

def to_s
  result = String.new

  mmr_min = @mmr_min > 0 ? @mmr_min.to_s : "Unknown"
  mmr_max = @mmr_max > 0 ? @mmr_max.to_s : "Unknown"

  result += "-------------------------------------------------------------------------------\n"
  result += "League: #{@@console.format(colour: @colour, message: "#{@league} #{@number}")}\n"
  result += "-------------------------------------------------------------------------------\n"
  result += "Maximum MMR: #{@@console.format(colour: @colour, message: mmr_max)}\n"
  result += "Minimum MMR: #{@@console.format(colour: @colour, message: mmr_min)}\n\n"

  return result
end

#upperObject



75
76
77
# File 'lib/sc2cli/subcommands/league/leaguetier.rb', line 75

def upper
  return @mmr_max
end