Created
March 30, 2009 13:05
-
-
Save vsalbaba/87776 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PilotMissionLog | |
attr_accessor :name, | |
:score, | |
:state, | |
:enemy_aircraft_kill, | |
:enemy_static_aircraft_kill, | |
:enemy_tank_kill, | |
:enemy_car_kill, | |
:enemy_artillery_kill, | |
:enemy_AAA_kill, | |
:enemy_wagon_kill, | |
:enemy_ship_kill, | |
:friend_aircraft_kill, | |
:friend_static_aircraft_kill, | |
:friend_tank_kill, | |
:friend_car_kill, | |
:friend_artillery_kill, | |
:friend_AAA_kill, | |
:friend_wagon_kill, | |
:friend_ship_kill, | |
:fire_bullets, | |
:hit_bullets, | |
:hit_air_bullets, | |
:fire_roskets, | |
:hit_roskets, | |
:fire_bombs, | |
:hit_bombs | |
def parse(pilot_stats) | |
@name = pilot_stats[1].delete("Name: ") | |
@score = pilot_stats[2].delete("Score: ").to_i | |
@state = pilot_stats[3].delete("State: ") | |
@enemy_aircraft_kill = pilot_stats[4].delete("Enemy Aircraft Kill: ") | |
@fire_bullets = pilot_stats[20].delete("Fire Bullets: ").to_i | |
@hit_air_bullets = pilot_stats[22].delete("Hit Air Bullets: ").to_i | |
end | |
end | |
class MissionLog | |
def parse(eventlog) | |
stats = eventlog.slice(eventlog.index("-------------------------------------------------------\n")..(eventlog.index("============ eof ==============")-2)) | |
result = [] | |
while pilot_stats = stats.slice!("-------------------------------------------------------\n".."Hit Bombs: 0\n" ) | |
result << PilotMissionLog.new.parse(pilot_stats) | |
end | |
return result | |
end | |
end | |
File.open("eventlog.lst", 'r+') do |file| #otevri kazdy soubor v rw modu | |
stats = file.readlines #nacti si vsechny radky | |
mission_log = MissionLog.new | |
p mission_log.parse(stats) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment