class AutoPilot::DocumentParser

Attributes

answer_id[R]
doc[R]
question_id[R]

Public Class Methods

new(doc, question_id, answer_id) click to toggle source
# File lib/auto_pilot/document_parser.rb, line 5
def initialize(doc, question_id, answer_id)
  @doc         = Nokogiri::HTML(doc)
  @question_id = question_id
  @answer_id   = answer_id
end

Public Instance Methods

answer_html() click to toggle source
# File lib/auto_pilot/document_parser.rb, line 27
def answer_html
  doc.css(xml_map[:answer]).inner_html
end
answer_text() click to toggle source
# File lib/auto_pilot/document_parser.rb, line 31
def answer_text
  doc.css(xml_map[:answer]).text
end
question_html() click to toggle source
# File lib/auto_pilot/document_parser.rb, line 19
def question_html
  doc.css(xml_map[:question]).inner_html
end
question_text() click to toggle source
# File lib/auto_pilot/document_parser.rb, line 23
def question_text
  doc.css(xml_map[:question]).text # you can also call inner_html for semantic formatting
end
title_html() click to toggle source
# File lib/auto_pilot/document_parser.rb, line 11
def title_html
  doc.css(xml_map[:h1]).inner_html
end
title_text() click to toggle source
# File lib/auto_pilot/document_parser.rb, line 15
def title_text
  doc.css(xml_map[:h1]).text
end

Private Instance Methods

xml_map() click to toggle source
# File lib/auto_pilot/document_parser.rb, line 37
def xml_map
  @xml_map ||= {
    h1:       '#question-header h1 .question-hyperlink',
    question: '#question .post-text',
    answer:   "#answer-#{answer_id} .post-text"
  }
end