def self.parse(src, chap)
items = []
indexs = []
headlines = []
inside_column = false
inside_block = nil
src.each do |line|
if line =~ %r{\A//[a-z]+.*\{\Z}
inside_block = true
next
elsif line =~ %r{\A//\}}
inside_block = nil
next
elsif inside_block
next
end
m = HEADLINE_PATTERN.match(line)
next if m.nil? || m[1].size > 10
next if m[4].strip.empty?
index = m[1].size - 2
if m[2] == 'column'
inside_column = true
next
elsif m[2] == '/column'
inside_column = false
next
end
inside_column = false if indexs.blank? || index <= indexs[-1]
next if inside_column
next unless index >= 0
if indexs.size > (index + 1)
indexs = indexs.take(index + 1)
headlines = headlines.take(index + 1)
end
(0..index).each { |i| indexs[i] = 0 if indexs[i].nil? } if indexs[index].nil?
indexs[index] += 1
headlines[index] = m[3].present? ? m[3].strip : m[4].strip
items.push Item.new(headlines.join('|'), indexs.dup, m[4].strip)
end
new(items, chap)
end