Guest User

Untitled

a guest
Jan 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. def parse_text(txt)
  2. txt = txt.split(/\n/)
  3. hash = {}
  4.  
  5. inblock = false
  6. block_name = nil
  7. block_content = nil
  8.  
  9. txt.each do |line|
  10. line.strip!
  11.  
  12. if !line.eql?("") && !line[0..1].eql?("#")
  13. if !inblock && line.include?("=begin")
  14. line.sub!(/\s*=begin/, "")
  15.  
  16. inblock = true
  17. block = line.to_sym
  18. end
  19.  
  20. if !inblock
  21. line = line.split(/\s*=>\s*/)
  22. hash[line[0].to_sym] = line[1]
  23. end
  24.  
  25. if inblock && line.include?("=end")
  26. inblock = false
  27. hash[block_name] = block_content
  28. block_name, block_content = nil
  29. end
  30.  
  31. if inblock
  32. block_content += line
  33. end
  34. end
  35. end
  36.  
  37. hash
  38. end
Add Comment
Please, Sign In to add comment