Class: Smartdown::Api::Question

Inherits:
Object
  • Object
show all
Defined in:
lib/smartdown/api/question.rb

Instance Method Summary collapse

Constructor Details

#initialize(elements) ⇒ Question

Returns a new instance of Question.



5
6
7
# File 'lib/smartdown/api/question.rb', line 5

def initialize(elements)
  @elements = elements
end

Instance Method Details

#bodyObject



17
18
19
20
# File 'lib/smartdown/api/question.rb', line 17

def body
  elements_before_smartdown = elements[1..-1].take_while{|element| !smartdown_element?(element)}
  build_govspeak(elements_before_smartdown)
end

#hintObject

TODO: deprecate



31
32
# File 'lib/smartdown/api/question.rb', line 31

def hint
end

#nameObject



13
14
15
# File 'lib/smartdown/api/question.rb', line 13

def name
  elements.find{ |element| element.class.to_s.include?("Smartdown::Model::Element::Question") }.name
end

#post_bodyObject



22
23
24
25
26
27
28
# File 'lib/smartdown/api/question.rb', line 22

def post_body
  elements_after_smartdown = elements.select{ |element| !next_node_element?(element) }
                                     .reverse
                                     .take_while{|element| !smartdown_element?(element)}
                                     .reverse
  build_govspeak(elements_after_smartdown)
end

#titleObject



9
10
11
# File 'lib/smartdown/api/question.rb', line 9

def title
  elements.first.content
end