Class: QStat::PlayerInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-qstat.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(player_info_line = nil) ⇒ PlayerInfo

Returns a new instance of PlayerInfo.



263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/ruby-qstat.rb', line 263

def initialize(player_info_line=nil)
  if player_info_line.nil?
    return self
  end

  if player_info_line =~ /^\s+(\S+)\s+(\S+)\s+(.*?s)\s+(.*)$/
    @frags = $1
    @time = $3
    @name = $4
    self
  else
    raise "not found playerinfo structure: #{player_info_line}"
  end
end

Instance Attribute Details

#fragsObject

Returns the value of attribute frags.



260
261
262
# File 'lib/ruby-qstat.rb', line 260

def frags
  @frags
end

#nameObject

Returns the value of attribute name.



259
260
261
# File 'lib/ruby-qstat.rb', line 259

def name
  @name
end

#timeObject

Returns the value of attribute time.



261
262
263
# File 'lib/ruby-qstat.rb', line 261

def time
  @time
end

Class Method Details

.create_from_xml(xml) ⇒ Object



278
279
280
281
282
283
284
# File 'lib/ruby-qstat.rb', line 278

def self.create_from_xml(xml)
  player_info = self.new
  player_info.name = xml.search("./name").text
  player_info.time = xml.search("./time").text
  player_info.frags = xml.search("./frags").text
  player_info
end

Instance Method Details

#time_to_iObject



286
287
288
# File 'lib/ruby-qstat.rb', line 286

def time_to_i
  qstat_timestr_to_seconds(@time)
end

#time_to_sObject



290
291
292
293
294
# File 'lib/ruby-qstat.rb', line 290

def time_to_s
  (minutes, seconds) = time_to_i.divmod(60)
  (hours, minutes) = minutes.divmod(60)
  "%02d:%02d" % [hours, minutes]
end

#to_sObject



296
297
298
# File 'lib/ruby-qstat.rb', line 296

def to_s
  "#<#{@name} #{time_to_s}>"
end