I have a text document that has formatted data in it, and I am
attempted to determine the best way to parse the data to break it up
into hashes that I can then write to my databases. I suppose my issue
is determining where to tell Ruby to STOP reading in data to write
into the database. The file would be similar to this:
User: Username
Phone: Phone number
Address: Address
Comments: Comments
Data1: Data
Data2: Data
Data3: Data
User: Username
Phone: Phone number
Address: Address
Comments: Comments
Data1: Data
Data2: Data
User: Username
Phone: Phone number
Address: Address
Comments: Comments
Data1: Data
Data2: Data
It’s not that difficult to chomp the \n and use a split to create a
hash in a loop, but how do tell Ruby to start a new database write
process if it hits a new “user” key value? Should I write a case
statement to check each line for a “user” key and use that line to
call a new instance of my database class/method? Is there a faster or
more efficient way?