# Parsing input using each\_line

**URL:** <https://www.ruby-forum.com/t/parsing-input-using-each-line/47626>\
**Category:** Rails\
**Created:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/parsing-input-using-each-line/47626 "2005-11-12T12:49:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![keckbug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/bc79bd/32.png) [@keckbug](https://www.ruby-forum.com/u/keckbug)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/parsing-input-using-each-line/47626/1 "2005-11-12T12:49:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![keckbug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/bc79bd/32.png) [@keckbug](https://www.ruby-forum.com/u/keckbug)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/parsing-input-using-each-line/47626/2 "2005-11-12T12:49:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![keckbug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/bc79bd/32.png) [@keckbug](https://www.ruby-forum.com/u/keckbug)\
**Post date:** [November 12, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/parsing-input-using-each-line/47626/3 "2005-11-12T12:49:58Z")

</div>

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.
