Class: TCLog::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/tclog.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Player

:nodoc:



163
164
165
166
# File 'lib/tclog.rb', line 163

def initialize(name) # :nodoc:
  @name = name
  @results = []
end

Instance Attribute Details

#nameObject (readonly)

This player’s name.



202
203
204
# File 'lib/tclog.rb', line 202

def name
  @name
end

#resultsObject (readonly)

This player’s round results. Use compact method to use Round#round_number.



206
207
208
# File 'lib/tclog.rb', line 206

def results
  @results
end

Instance Method Details

#add_result(n, score) ⇒ Object

:nodoc:



168
169
170
# File 'lib/tclog.rb', line 168

def add_result(n, score) # :nodoc:
  @results[n] = score.merge(:round => n); self
end

#push_result(i) ⇒ Object

:nodoc:



197
198
199
# File 'lib/tclog.rb', line 197

def push_result(i) # :nodoc:
  @results[i] = nil
end

#totalObject

Returns this player’s total score.



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/tclog.rb', line 173

def total
  a = @results.compact.inject({
    :name  => @name,
    :kill  => 0,
    :death => 0,
    :sui   => 0,
    :tk    => 0,
    :eff   => 0,
    :dg    => 0,
    :dr    => 0,
    :td    => 0,
    :score => 0,
    :rate  => 0
  }) do |r,i|
    [:kill,:death,:sui,:tk,:eff,:dg,:dr,:td,:score].each do |l|
      r[l] += i[l]
    end
    r
  end
  a[:rate] = (a[:dg].to_i-a[:dr].to_i)/100.0
  a[:kd] = a[:kill].to_f / a[:death].to_f
  a
end