Class: Smartdown::Api::PreviousQuestionPage
- Inherits:
-
Object
- Object
- Smartdown::Api::PreviousQuestionPage
- Defined in:
- lib/smartdown/api/previous_question_page.rb
Instance Attribute Summary collapse
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(node, responses) ⇒ PreviousQuestionPage
constructor
A new instance of PreviousQuestionPage.
- #questions ⇒ Object
Constructor Details
#initialize(node, responses) ⇒ PreviousQuestionPage
Returns a new instance of PreviousQuestionPage.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/smartdown/api/previous_question_page.rb', line 9 def initialize(node, responses) node_elements = node.elements.clone headings = node_elements.select { |element| element.is_a? Smartdown::Model::Element::MarkdownHeading } @title = headings.first.content.to_s if headings.first nb_questions = node_elements.select{ |element| element.class.to_s.include?("Smartdown::Model::Element::Question") }.count if headings.count > nb_questions node_elements.delete(headings.first) #Remove page title end @elements = node_elements @responses = responses end |
Instance Attribute Details
#title ⇒ Object (readonly)
Returns the value of attribute title.
7 8 9 |
# File 'lib/smartdown/api/previous_question_page.rb', line 7 def title @title end |
Instance Method Details
#questions ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/smartdown/api/previous_question_page.rb', line 25 def questions elements.slice_before do |element| element.is_a? Smartdown::Model::Element::MarkdownHeading end.each_with_index.map do |question_element_group, index| Smartdown::Api::PreviousQuestion.new(question_element_group, responses[index]) end end |