Class: RaceData
Instance Attribute Summary collapse
-
#racers ⇒ Object
Returns the value of attribute racers.
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
-
#initialize ⇒ RaceData
constructor
A new instance of RaceData.
- #parseStringToRaceData(aString) ⇒ Object
- #printRaceData ⇒ Object
Constructor Details
#initialize ⇒ RaceData
Returns a new instance of RaceData.
34 35 36 37 38 39 40 41 |
# File 'lib/race_data.rb', line 34 def initialize() @data = [128,129,128,128,129,130,128,135,143,143,'#'.to_i] @rawdata = [] @testinput = "[email protected]" + @data.pack('c*') @racers = [[],[],[],[]] @test = false @time = 0 end |
Instance Attribute Details
#racers ⇒ Object
Returns the value of attribute racers.
32 33 34 |
# File 'lib/race_data.rb', line 32 def racers @racers end |
#time ⇒ Object
Returns the value of attribute time.
32 33 34 |
# File 'lib/race_data.rb', line 32 def time @time end |
Instance Method Details
#parseStringToRaceData(aString) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/race_data.rb', line 50 def parseStringToRaceData(aString) aString = @testinput if @test == true if aString =~ /!(\d+)@([a-q]*)#/ # returns the time in $1, and the data in $2 time = $1.to_i @rawdata = $2.unpack('C*') @rawdata.each_with_index{|data,x| current_time = time+(x*MILLIS_PER_FRAME) if (data - ?a)[0] == 1 @racers[0].push(current_time) end if (data - ?a)[1] == 1 @racers[1].push(current_time) end if (data - ?a)[2] == 1 @racers[2].push(current_time) end if (data - ?a)[3] == 1 @racers[3].push(current_time) end @time = current_time } #print(@rawdata, "\n") #printRaceData() #debug("test") end end |
#printRaceData ⇒ Object
43 44 45 46 47 48 |
# File 'lib/race_data.rb', line 43 def printRaceData() puts "Red:",@racers[0].join(' ') puts "Blue:",@racers[1].join(' ') puts "Green:",@racers[2].join(' ') puts "Yellow:",@racers[3].join(' ') end |