Class: SC2Cli::Subcommands::LeagueShared::LeagueTiers

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, colour:, json:) ⇒ LeagueTiers

Returns a new instance of LeagueTiers.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sc2cli/subcommands/league/leaguetiers.rb', line 28

def initialize(name:, colour:, json:)
  @name   = name
  @colour = colour
  @tiers  = Array.new

  if json.key?("tier") then
    tiers = json["tier"]
    @@console.fatal("Returned league information for: #{name} tiers is not an array!") unless tiers.kind_of?(Array)

    tiers.each do |tier|
      tier = LeagueTier.new(league: @name, colour: @colour, json: tier)
      add(tier: tier)
    end
  end
end

Instance Attribute Details

#colourObject (readonly)

Returns the value of attribute colour.



23
24
25
# File 'lib/sc2cli/subcommands/league/leaguetiers.rb', line 23

def colour
  @colour
end

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/sc2cli/subcommands/league/leaguetiers.rb', line 24

def name
  @name
end

Instance Method Details

#add(tier:) ⇒ Object



46
47
48
49
# File 'lib/sc2cli/subcommands/league/leaguetiers.rb', line 46

def add(tier:)
  @tiers << tier if tier.kind_of?(LeagueTier)
  @tiers.sort_by!{ |tier| tier.id }
end

#to_sObject



53
54
55
56
57
58
59
60
61
# File 'lib/sc2cli/subcommands/league/leaguetiers.rb', line 53

def to_s
  result = String.new

  @tiers.each do |tier|
    result += tier.to_s
  end

  return result
end