Class: Smartdown::Api::Node

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

Direct Known Subclasses

Coversheet, Outcome, QuestionPage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Node

Returns a new instance of Node.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/smartdown/api/node.rb', line 7

def initialize(node)
  node_elements = node.elements.clone
  headings = node_elements.select { |element|
    element.is_a? Smartdown::Model::Element::MarkdownHeading
  }
  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
    @title = headings.first.content.to_s
  end
  @elements = node_elements
  @front_matter = node.front_matter
  @name = node.name
end

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



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

def elements
  @elements
end

#front_matterObject (readonly)

Returns the value of attribute front_matter.



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

def front_matter
  @front_matter
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

Instance Method Details

#bodyObject



24
25
26
27
# File 'lib/smartdown/api/node.rb', line 24

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

#devolved_bodyObject



29
30
31
32
# File 'lib/smartdown/api/node.rb', line 29

def devolved_body
  elements_after_smartdown = elements.drop_while{|element| !smartdown_element?(element)}
  build_govspeak(elements_after_smartdown)
end

#next_nodesObject



34
35
36
# File 'lib/smartdown/api/node.rb', line 34

def next_nodes
  elements.select{ |element| element.is_a? Smartdown::Model::NextNodeRules }
end

#permitted_next_nodesObject



38
39
40
# File 'lib/smartdown/api/node.rb', line 38

def permitted_next_nodes
  next_nodes
end