class QuakeliveApi::GameTime

Attributes

ranked[RW]
unranked[RW]

Public Class Methods

new(unparsed_string) click to toggle source

accepts unparsed string directly from QL profile, for example:

  • Ranked Time: 21:50 Unranked Time: 04:54

  • Ranked Time: 50.06:18:30 Unranked Time: 02:31:02

# File lib/quakelive_api/game_time.rb, line 14
def initialize(unparsed_string)
  matches = unparsed_string.match(/Ranked Time: ([\d:.]+) Unranked Time: ([\d:.]+)/)
  return unless matches

  @ranked   = reverse_match(matches[1])
  @unranked = reverse_match(matches[2])
end

Public Instance Methods

==(other) click to toggle source
# File lib/quakelive_api/game_time.rb, line 22
def ==(other)
  return ranked == other.ranked && unranked == other.unranked
end

Private Instance Methods

reverse_match(string) click to toggle source
# File lib/quakelive_api/game_time.rb, line 28
def reverse_match(string)
  attrs = string.split(/\.|:/).reverse.map { |a| a.to_i }
  (4 - attrs.size).times { attrs << 0 }
  Interval.new(*attrs)
end