Parsing input using each_line


#1

In a certain MMO I play(Hi guys!), after a player dies or a player kills
another player, a message is sent in the following format:

2005.11.08 04:49:00

Victim: im187
Alliance: Unknown
Corporation: Rebellion Corp
Destroyed Type: Ferox
Solar System: Polfaly
System Security Level: 0.8

Involved parties:

Name: RollinDutchMasters
Security Status: -1.9
Alliance: Unknown
Corporation: Einherjar Rising
Ship Type: Claw
Weapon Type: ‘Limos’ Rocket Launcher I

Name: Frey Jorgurand (laid the final blow)
Security Status: 0.1
Alliance: Unknown
Corporation: Einherjar Rising
Ship Type: Rifter
Weapon Type: Bloodclaw Light Missile I

Name: Antfred von’Ricktofen
Security Status: 0.1
Alliance: Unknown
Corporation: Einherjar Rising
Ship Type: Punisher
Weapon Type: Gatling Afocal Maser I

Name: Exodus Ronin
Security Status: 0.2
Alliance: Unknown
Corporation: Einherjar Rising
Ship Type: Capsule
Weapon Type: Standard Missile Launcher I

Name: numbers
Security Status: 0.1
Alliance: Unknown
Corporation: Einherjar Rising
Ship Type: Punisher
Weapon Type: Dual Light Beam Laser I

Name: Humkah Chanz
Security Status: 0.1
Alliance: Unknown
Corporation: Einherjar Rising
Ship Type: Punisher
Weapon Type: Dual Light Pulse Laser I


#2

Aaron Keck wrote:

System Security Level: 0.8
Name: Frey Jorgurand (laid the final blow)
Ship Type: Punisher
Security Status: 0.1
Weapon Type: Dual Light Pulse Laser I
parsing would be helpful.
I’d start with something like

class Thing
attr_accessor :alliance, :corporation

def initialize(alliance, corporation)
@alliance = alliance
@corporation = corporation
end
end

class Victim < Thing
attr_accessor :dest_type, :solar_system, :sec_level

def initialize(alliance, corporation, dest_type, solar_system,
sec_level)
@alliance = alliance
@corporation = corporation
@det_type = dest_type
@solar_system = solar_system
@sec_level = sec_level
end
end

class Party < Thing
attr_accessor :sec_stat, :ship_type, :weapon_type
def initialize(alliance, corporation, sec_stat, ship_type,
weapon_type)
@alliance = alliance
@corporation = corporation
@sec_stat = sec_stat
@ship_type = ship_type
@weapon_type = :weapon_type
end
end

class Parties < Array
end

And then look at String classes etc for how to read the data into your
datastructures


#3

On Nov 10, 2005, at 2:00 AM, Aaron Keck wrote:

Victim: im187
Alliance: Unknown
Corporation: Rebellion Corp
Destroyed Type: Ferox
Solar System: Polfaly
System Security Level: 0.8

You should be able to pretty easily chunk it out into blocks like this,
then you might notice that
it looks a little like … valid YAML! Try feeding the above block of
text to YAML.load, I think you’ll
find the results convenient (for kicks also try YAML.load(svn info)
in a subversion repository).

Involved parties:

Of course you will have to separate the blocks, because that one isn’t
valid YAML, and the blocks
below repeat, but it should be pretty simple to handle.