class Smartdown::Api::Question
Attributes
elements[R]
Public Class Methods
new(elements)
click to toggle source
# File lib/smartdown/api/question.rb, line 5 def initialize(elements) @elements = elements end
Public Instance Methods
body()
click to toggle source
# 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
hint()
click to toggle source
TODO: deprecate
# File lib/smartdown/api/question.rb, line 31 def hint end
name()
click to toggle source
# 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_body()
click to toggle source
# 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
title()
click to toggle source
# File lib/smartdown/api/question.rb, line 9 def title elements.first.content end
Private Instance Methods
build_govspeak(elements)
click to toggle source
# File lib/smartdown/api/question.rb, line 51 def build_govspeak(elements) markdown_elements = elements.select { |element| markdown_element?(element) } markdown_elements.map(&:content).join("") unless markdown_elements.empty? end
markdown_element?(element)
click to toggle source
# File lib/smartdown/api/question.rb, line 38 def markdown_element?(element) (element.is_a? Smartdown::Model::Element::MarkdownLine) || (element.is_a? Smartdown::Model::Element::MarkdownHeading) end
next_node_element?(element)
click to toggle source
# File lib/smartdown/api/question.rb, line 47 def next_node_element?(element) (element.is_a? Smartdown::Model::NextNodeRules) end
smartdown_element?(element)
click to toggle source
# File lib/smartdown/api/question.rb, line 43 def smartdown_element?(element) !markdown_element?(element) end