I've got a data file that looks like this:
Things
├── Foo
│ ├── 1. Item One
│ ├── 2. Item Two
│ ├── 3. Item Three
│ ├── 4. Item Four
│ ├── 5. Item Five
│ └── 6. Item Six
├── Bar
│ ├── 1. Item Seven
│ ├── 2. Item Eight
│ ├── 3. Item Nine
What I'm trying to do is find a certain string, the number associated with it, and also the subheading that is a part of ('Foo' or 'Bar')
It's pretty easy to grab the item and the number:
str = "Item One"
data.each_line do |line|
if line =~ /#{str}/
/(?<num>\d).\s(?<item>.*)/ =~ line
end
end
But I'm not sure how to get the subheading. What I was thinking is that once I found the line, I could count up from that point using the number. Is there a readlines or a seek command or some such that could do this?
Appreciate the help!