Class: Omega::ScoreboardEntry

Inherits:
Base
  • Object
show all
Defined in:
lib/omega/scoreboard.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#data

Instance Method Summary collapse

Constructor Details

#initialize(client, entry) ⇒ ScoreboardEntry

Returns a new instance of ScoreboardEntry.



10
11
12
13
14
15
# File 'lib/omega/scoreboard.rb', line 10

def initialize(client, entry)
  @username = entry[:username]
  @client = client
  @problems = entry[:problems] || []
  @data = entry
end

Instance Attribute Details

#problemsObject

Returns the value of attribute problems.



7
8
9
# File 'lib/omega/scoreboard.rb', line 7

def problems
  @problems
end

#usernameObject (readonly)

Returns the value of attribute username.



8
9
10
# File 'lib/omega/scoreboard.rb', line 8

def username
  @username
end

Instance Method Details

#<=>(other) ⇒ Object



31
32
33
# File 'lib/omega/scoreboard.rb', line 31

def <=>(other)
  other.data[:total][:points] <=> @data[:total][:points]
end

#merge(score) ⇒ Object



17
18
19
20
21
22
# File 'lib/omega/scoreboard.rb', line 17

def merge(score)
  result = clone
  result.problems += score.problems
  result.data[:total][:points] += score.data[:total][:points]
  result
end

#score_for(name) ⇒ Object



35
36
37
38
39
40
# File 'lib/omega/scoreboard.rb', line 35

def score_for(name)
  problems.each do |problem|
    return problem if problem[:alias] == name
  end
  nil
end

#simple_displayObject



24
25
26
27
28
29
# File 'lib/omega/scoreboard.rb', line 24

def simple_display
  {
    username: @data[:username],
    score: @data[:total][:points]
  }
end