Class: SRL::Game

Inherits:
Object
  • Object
show all
Includes:
Unmarshalable
Defined in:
lib/srl/game.rb

Overview

Summary information about a game run on SRL.

Defined Under Namespace

Classes: Runner, Statistics

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Unmarshalable

included

Instance Attribute Details

#abbrevObject (readonly) Also known as: abbreviation, short_name

This game’s abbreviation, as used by RaceBot.



14
15
16
# File 'lib/srl/game.rb', line 14

def abbrev
  @abbrev
end

#leadersObject

This game’s leaderboard, as an array of Players.

While generally sorted by rank, this method does not guarantee the order of the players return.

If you absolutely need them sorted, use the ‘leaders_by_rank` method or call `sort_by(&:rank)` on this value.



38
39
40
# File 'lib/srl/game.rb', line 38

def leaders
  @leaders
end

#leadersCountObject (readonly) Also known as: leaders_count, num_leaders

The amount of ranked players on this game’s leaderboard.



27
28
29
# File 'lib/srl/game.rb', line 27

def leadersCount
  @leadersCount
end

#nameObject (readonly)

This game’s complete name.



11
12
13
# File 'lib/srl/game.rb', line 11

def name
  @name
end

#oidObject (readonly) Also known as: game_id

This game’s ID as per the SRL data.



7
8
9
# File 'lib/srl/game.rb', line 7

def oid
  @oid
end

#popularityObject (readonly)

This game’s popularity rating, according to SRL data.



19
20
21
# File 'lib/srl/game.rb', line 19

def popularity
  @popularity
end

#popularityrankObject (readonly) Also known as: popularity_rank

This game’s position in the popularity contest, according to SRL data.



23
24
25
# File 'lib/srl/game.rb', line 23

def popularityrank
  @popularityrank
end

#statsObject Also known as: statistics

Statistics about this game. Things like the number of races, number of players, total time played and raced.

SEE

SRL::Statistics



47
48
49
# File 'lib/srl/game.rb', line 47

def stats
  @stats
end

Instance Method Details

#leaders_by_rank(dir = :asc) ⇒ Object

An array of players on this game’s leaderboard, sorted by their rank.

Raises:

  • (ArgumentError)


59
60
61
62
63
64
# File 'lib/srl/game.rb', line 59

def leaders_by_rank(dir = :asc)
  raise ArgumentError unless %i(asc desc).include?(dir)
  
  dir == :asc ? leaders.sort_by(&:rank) 
              : leaders.sort_by(&:rank).reverse
end