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 ---------------------------- As you can see, it''s a pretty simple format. I''m brand spankin new to ruby, and haven''t done much beyond the various tutorials, and I''m working on a program to accept the above, copy/pasted to a text_area, parse it for fields, and store the fields in a database. I''m looking for help writing the engine for the parsing script. I suspect it involves the use if str.each_line, but I''m not quite sure how, and some general direction or tips, particularly examples of similar parsing would be helpful. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Aaron Keck wrote:> 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 > > ---------------------------- > > As you can see, it''s a pretty simple format. I''m brand spankin new to > ruby, and haven''t done much beyond the various tutorials, and I''m > working on a program to accept the above, copy/pasted to a text_area, > parse it for fields, and store the fields in a database. I''m looking > for help writing the engine for the parsing script. I suspect it > involves the use if str.each_line, but I''m not quite sure how, and > some general direction or tips, particularly examples of similar > 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
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.8You 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. -- Scott Barron Lunchbox Software http://lunchboxsoftware.com http://lunchroom.lunchboxsoftware.com http://rubyi.st _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails