parser.rb 718 B

12345678910111213141516171819202122232425262728293031323334
  1. #
  2. # parser.rb
  3. # MacBidwatcher
  4. #
  5. # Created by Morgan Schweers on 7/24/11.
  6. # Copyright 2011 CyberFOX Software, Inc. All rights reserved.
  7. #
  8. require 'nokogiri'
  9. class Parser
  10. # @param page The HTML of the page to parse
  11. def initialize(page)
  12. @page = Nokogiri::HTML.parse(page)
  13. end
  14. def match_set(match)
  15. match_step = 0
  16. result = []
  17. @page.root.traverse do |node|
  18. if node.text?
  19. if node.text.strip.match(match[match_step])
  20. result << node.text
  21. match_step += 1
  22. return result if match_step == match.length
  23. elsif !node.text.strip.empty? && !result.empty?
  24. result.clear
  25. match_step = 0
  26. end
  27. end
  28. end
  29. nil
  30. end
  31. end