Class: Smartdown::Api::Node
- Inherits:
-
Object
- Object
- Smartdown::Api::Node
- Defined in:
- lib/smartdown/api/node.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#front_matter ⇒ Object
readonly
Returns the value of attribute front_matter.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #body ⇒ Object
- #devolved_body ⇒ Object
-
#initialize(node) ⇒ Node
constructor
A new instance of Node.
- #next_nodes ⇒ Object
- #permitted_next_nodes ⇒ Object
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
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
5 6 7 |
# File 'lib/smartdown/api/node.rb', line 5 def elements @elements end |
#front_matter ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/smartdown/api/node.rb', line 5 def name @name end |
#title ⇒ Object (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
#body ⇒ Object
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_body ⇒ Object
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_nodes ⇒ Object
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_nodes ⇒ Object
38 39 40 |
# File 'lib/smartdown/api/node.rb', line 38 def permitted_next_nodes next_nodes end |