Class: Gettc::Parser
- Inherits:
-
Object
- Object
- Gettc::Parser
- Defined in:
- lib/gettc/parse.rb
Instance Method Summary collapse
-
#initialize(downloader) ⇒ Parser
constructor
A new instance of Parser.
- #parse(problem_id) ⇒ Object
Constructor Details
Instance Method Details
#parse(problem_id) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/gettc/parse.rb', line 16 def parse(problem_id) doc = Hpricot(@downloader.download_statement(problem_id)) @problem = Problem.new @problem.id = problem_id @problem.name = parse_name(doc.search("tr/td.statTextBig").html) html = doc.search("td.problemText/table").html has_notes = true has_constraints = true has_examples = true _, x = self.class.indexes(html, self.class.h3("Problem Statement")) y, z = self.class.indexes(html, self.class.h3("Definition")) parse_statement(html[x .. y]) x, y = self.class.indexes(html, self.class.h3("Notes")) if x.nil? has_notes = false x, y = self.class.indexes(html, self.class.h3("Constraints")) if x.nil? has_constraints = false x, y = self.class.indexes(html, self.class.h3("Examples")) if x.nil? has_examples = false x = -2 end end end parse_definitions(html[z .. x]) if has_notes z, x = self.class.indexes(html, self.class.h3("Constraints")) if z.nil? has_constraints = false z, x = self.class.indexes(html, self.class.h3("Examples")) if z.nil? has_examples = false z = - 2 end end parse_notes(html[y .. z]) x, y = z, x end if has_constraints z, x = self.class.indexes(html, self.class.h3("Examples")) if z.nil? has_examples = false z = -2 end parse_constraints(html[y .. z]) end parse_examples(html[x .. -2]) if has_examples parse_details(doc) @problem end |