Class: AutoPilot::DocumentParser

Inherits:
Object
  • Object
show all
Defined in:
lib/auto_pilot/document_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, question_id, answer_id) ⇒ DocumentParser

Returns a new instance of DocumentParser.



5
6
7
8
9
# 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

Instance Attribute Details

#answer_idObject (readonly)

Returns the value of attribute answer_id.



4
5
6
# File 'lib/auto_pilot/document_parser.rb', line 4

def answer_id
  @answer_id
end

#docObject (readonly)

Returns the value of attribute doc.



4
5
6
# File 'lib/auto_pilot/document_parser.rb', line 4

def doc
  @doc
end

#question_idObject (readonly)

Returns the value of attribute question_id.



4
5
6
# File 'lib/auto_pilot/document_parser.rb', line 4

def question_id
  @question_id
end

Instance Method Details

#answer_htmlObject



27
28
29
# File 'lib/auto_pilot/document_parser.rb', line 27

def answer_html
  doc.css(xml_map[:answer]).inner_html
end

#answer_textObject



31
32
33
# File 'lib/auto_pilot/document_parser.rb', line 31

def answer_text
  doc.css(xml_map[:answer]).text
end

#question_htmlObject



19
20
21
# File 'lib/auto_pilot/document_parser.rb', line 19

def question_html
  doc.css(xml_map[:question]).inner_html
end

#question_textObject



23
24
25
# 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_htmlObject



11
12
13
# File 'lib/auto_pilot/document_parser.rb', line 11

def title_html
  doc.css(xml_map[:h1]).inner_html
end

#title_textObject



15
16
17
# File 'lib/auto_pilot/document_parser.rb', line 15

def title_text
  doc.css(xml_map[:h1]).text
end