Advertisement
Guest User

Untitled

a guest
Aug 20th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #!/usr/bin/evn ruby
  2.  
  3. def parse_line remainder_of_line
  4.  
  5. puts "Processing: #{remainder_of_line}"
  6.  
  7. # Save a copy of the initial input for later comparison
  8. initial_snapshot = remainder_of_line.dup
  9.  
  10. # Look for known pattern matches, removing them if found
  11. if remainder_of_line.gsub!(/^(d+) 0 -1 1 (d+) d+s*/, '')
  12. puts " - Matched format 1 - found: #{$1} - #{$2}nn"
  13. elsif remainder_of_line.gsub!(/^d+ 0 -1 2 (d+) d+s*/, '')
  14. puts " - Matched format 2 - found: #{$1}nn"
  15.  
  16. ### More patterns here.
  17. end
  18.  
  19. # If noting changed, then no matches were found.
  20. if initial_snapshot.eql? remainder_of_line
  21. puts " - Line still has data but no matches found. (Left with: #{remainder_of_line}nn"
  22. # Keep going if there is anything left.
  23. elsif !remainder_of_line.empty?
  24. parse_line remainder_of_line
  25. end
  26.  
  27. end
  28.  
  29.  
  30. line = "11 0 -1 2 13560 2 11 0 -1 2 13564 2 11 0 -1 1 36880 106 91 0 -1 1 36881 106 36881 106 91 1 13556 2 36880 106 36880 106 11 1 734 11 0 -1 1 36884 106 91 0 -1 1 36885 106 36885 106 91 1 13556 2 36884 106 36884 106 11 1 735 13556 2 31 18 799 13556 2 31 25 799 "
  31.  
  32. parse_line line
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement