How to copy this portion of a text file out and put into a hash using rails? (VATsim datafile)
- by Rusty Broderick
Hi
I'm trying to work out how i can cut out the section between !CLIENTS and the '; ;' and then to parse it into a hash in order to make an xml file. Honestly have no idea how to do it.
The file is as follows: vatsim-data.txt original file here
; Created at 30/12/2010 01:29:14 UTC by Data Server V4.0
;
; Data is the property of VATSIM.net and is not to be used for commercial purposes without the express written permission of the VATSIM.net Founders or their designated agent(s ).
;
; Sections are:
; !GENERAL contains general settings
; !CLIENTS contains informations about all connected clients
; !PREFILE contains informations about all prefiled flight plans
; !SERVERS contains a list of all FSD running servers to which clients can connect
; !VOICE SERVERS contains a list of all running voice servers that clients can use
;
; Data formats of various sections are:
; !GENERAL section - VERSION is this data format version
; RELOAD is time in minutes this file will be updated
; UPDATE is the last date and time this file has been updated. Format is yyyymmddhhnnss
; ATIS ALLOW MIN is time in minutes to wait before allowing manual Atis refresh by way of web page interface
; CONNECTED CLIENTS is the number of clients currently connected
; !CLIENTS section - callsign:cid:realname:clienttype:frequency:latitude:longitude:altitude:groundspeed:planned_aircraft:planned_tascruise:planned_depairport:planned_altitude:planned_destairport:server:protrevision:rating:transponder:facilitytype:visualrange:planned_revision:planned_flighttype:planned_deptime:planned_actdeptime:planned_hrsenroute:planned_minenroute:planned_hrsfuel:planned_minfuel:planned_altairport:planned_remarks:planned_route:planned_depairport_lat:planned_depairport_lon:planned_destairport_lat:planned_destairport_lon:atis_message:time_last_atis_received:time_logon:heading:QNH_iHg:QNH_Mb:
; !PREFILE section - callsign:cid:realname:clienttype:frequency:latitude:longitude:altitude:groundspeed:planned_aircraft:planned_tascruise:planned_depairport:planned_altitude:planned_destairport:server:protrevision:rating:transponder:facilitytype:visualrange:planned_revision:planned_flighttype:planned_deptime:planned_actdeptime:planned_hrsenroute:planned_minenroute:planned_hrsfuel:planned_minfuel:planned_altairport:planned_remarks:planned_route:planned_depairport_lat:planned_depairport_lon:planned_destairport_lat:planned_destairport_lon:atis_message:time_last_atis_received:time_logon:heading:QNH_iHg:QNH_Mb:
; !SERVERS section - ident:hostname_or_IP:location:name:clients_connection_allowed:
; !VOICE SERVERS section - hostname_or_IP:location:name:clients_connection_allowed:type_of_voice_server:
;
; Field separator is : character
;
;
!GENERAL:
VERSION = 8
RELOAD = 2
UPDATE = 20101230012914
ATIS ALLOW MIN = 5
CONNECTED CLIENTS = 515
;
;
!VOICE SERVERS:
voice2.vacc-sag.org:Nurnberg:Europe-CW:1:R:
voice.vatsim.fi:Finland - Sponsored by Verkkokauppa.com and NBL Solutions:Finland:1:R:
rw.liveatc.net:USA, California:Liveatc:1:R:
rw1.vatpac.org:Melbourne, Australia:Oceania:1:R:
spain.vatsim.net:Spain:Vatsim Spain Server:1:R:
voice.nyartcc.org:Sponsored by NY ARTCC:NY-ARTCC:1:R:
voice.zhuartcc.net:Sponsored by Houston ARTCC:ZHU-ARTCC:1:R:
;
;
!CLIENTS:
01PD:1090811:prentis gibbs KJFK:PILOT::40.64841:-73.81030:15:0::0::::USA-E:100:1:1200::::::::::::::::::::20101230010851:28:30.1:1019:
4X-BRH:1074589:george sandoval LLJR:PILOT::50.05618:-125.84429:10819:206:C337/G:150:CYAL:FL120:CCI9:EUROPE-C2:100:1:6043:::2:I:110:110:1:26:2:59:: /T/:DCT:0:0:0:0:::20101230005323:129:29.76:1007:
50125:1109107:Dave Frew KEDU:PILOT::46.52736:-121.95317:23877:471:B/B744/F:530:KTCM:30000:KLSV:USA-E:100:1:7723:::1:I:0:116:0:0:0:0:::GPS DIRECT.:0:0:0:0:::20101230012346:164:29.769:1008:
85013:1126003:Dmitry Abramov UWWW:PILOT::76.53819:71.54782:33444:423:T/ZZZZ/G:500:UUDD:FL330:ULAA:EUROPE-C2:100:1:2200:::2:I:0:2139:0:0:0:0:ULLI::BITSA DCT WM/N0485S1010 DCT KS DCT NE R22 ULWW B153 LAPEK B210 SU G476 OLATA:0:0:0:0:::20101229215815:62:53.264:1803:
;
;
!SERVERS:
EUROPE-C2:88.198.19.202:Europe:Center Europe Server Two:1:
;
; END
I want to format the html with the tags with client being the parent and the nested tags as follows:
callsign:cid:realname:clienttype:frequency:latitude:longitude:altitude:groundspeed:planned_aircraft:planned_tascruise:planned_depairport:planned_altitude:planned_destairport:server:protrevision:rating:transponder:facilitytype:visualrange:planned_revision:planned_flighttype:planned_deptime:planned_actdeptime:planned_hrsenroute:planned_minenroute:planned_hrsfuel:planned_minfuel:planned_altairport:planned_remarks:planned_route:planned_depairport_lat:planned_depairport_lon:planned_destairport_lat:planned_destairport_lon:atis_message:time_last_atis_received:time_logon:heading:QNH_iHg:QNH_Mb:
Any help in solving this would be much appreciated!