Class: QStat::PlayerInfo
- Inherits:
-
Object
- Object
- QStat::PlayerInfo
- Defined in:
- lib/ruby-qstat.rb
Instance Attribute Summary collapse
-
#frags ⇒ Object
Returns the value of attribute frags.
-
#name ⇒ Object
Returns the value of attribute name.
-
#time ⇒ Object
Returns the value of attribute time.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(player_info_line = nil) ⇒ PlayerInfo
constructor
A new instance of PlayerInfo.
- #time_to_i ⇒ Object
- #time_to_s ⇒ Object
- #to_s ⇒ Object
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
#frags ⇒ Object
Returns the value of attribute frags.
260 261 262 |
# File 'lib/ruby-qstat.rb', line 260 def frags @frags end |
#name ⇒ Object
Returns the value of attribute name.
259 260 261 |
# File 'lib/ruby-qstat.rb', line 259 def name @name end |
#time ⇒ Object
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_i ⇒ Object
286 287 288 |
# File 'lib/ruby-qstat.rb', line 286 def time_to_i qstat_timestr_to_seconds(@time) end |
#time_to_s ⇒ Object
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_s ⇒ Object
296 297 298 |
# File 'lib/ruby-qstat.rb', line 296 def to_s "#<#{@name} #{time_to_s}>" end |