I have to go through the following text and match each of the following, and break them apart into separate records to save to a database. So this text:
ESTIMATED MINIMUM CENTRAL PRESSURE 951 MB
EYE DIAMETER 12 NM
MAX SUSTAINED WINDS 105 KT WITH GUSTS TO 130 KT
64 KT....... 25NE 25SE 25SW 25NW
50 KT....... 60NE 30SE 30SW 60NW
34 KT....... 75NE 50SE 50SW 75NW
12 FT SEAS.. 75NE 50SE 50SW 75NW
ALL QUADRANT RADII IN NAUTICAL MILES
REPEAT...CENTER LOCATED NEAR 25.5N 73.4W AT 23/0900Z
AT 23/0600Z CENTER WAS LOCATED NEAR 25.5N 72.6W
FORECAST VALID 23/1800Z 25.4N 75.6W
MAX WIND 110 KT...GUSTS 135 KT
50 KT... 60NE 60SE 60SW 60NW
34 KT... 75NE 75SE 75SW 75NW
FORECAST VALID 24/0600Z 25.5N 78.8W
MAX WIND 115 KT...GUSTS 140 KT
50 KT... 60NE 60SE 60SW 60NW
34 KT...100NE 100SE 100SW 100NW
FORECAST VALID 24/1800Z 25.8N 81.8W
MAX WIND 85 KT...GUSTS 105 KT
50 KT... 60NE 60SE 60SW 60NW
34 KT...100NE 100SE 100SW 100NW
... should end up looking something like the following:
forecastAdvisory = {
:centralPressure => 951,
:eyeDiameter => 12,
:vMax => 105,
:gMax => 130,
:windRadii => {
64 => [25, 25, 25, 25],
50 => [60, 30, 30, 60],
34 => [75, 50, 50, 75],
12 => [75, 50, 50, 75]
},
:forecastTrack => {
12 => {
:latitude => 25.4,
:longitude => 75.6,
:vMax => 110,
:gMax => 135
:windRadii => {
50 => [60, 60, 60, 60]
34 => [75, 75, 75, 75]
}
},
24 => {
:latitude => 25.5,
:longitude => 78.8,
:vMax => 115,
:gMax => 140
:windRadii => {
50 => [60, 60, 60, 60]
34 => [100, 100, 100, 100]
}
},
36 => {
:latitude => 25.8,
:longitude => 81.8,
:vMax => 85,
:gMax => 105
:windRadii => {
50 => [60, 60, 60, 60]
34 => [100, 100, 100, 100]
}
}
}
}
I know I could probably use the scan
method for String
in Ruby, but I'm not sure on how I could go through the file in order and get these values and parse them correctly.
UPDATE: Here are a few sample files I will be parsing using File.open
, just for reference: