Class: Smartdown::Model::Node
- Inherits:
-
Struct
- Object
- Struct
- Smartdown::Model::Node
- Defined in:
- lib/smartdown/model/node.rb
Instance Attribute Summary collapse
-
#elements ⇒ Object
Returns the value of attribute elements.
-
#front_matter ⇒ Object
Returns the value of attribute front_matter.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(name, elements, front_matter = nil) ⇒ Node
constructor
A new instance of Node.
- #is_outcome_page_node? ⇒ Boolean
- #is_question_node? ⇒ Boolean
- #is_start_page_node? ⇒ Boolean
- #next_node_rules ⇒ Object
- #post_body ⇒ Object
- #questions ⇒ Object
- #start_button ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(name, elements, front_matter = nil) ⇒ Node
6 7 8 |
# File 'lib/smartdown/model/node.rb', line 6 def initialize(name, elements, front_matter = nil) super(name, elements, front_matter || Smartdown::Model::FrontMatter.new) end |
Instance Attribute Details
#elements ⇒ Object
Returns the value of attribute elements
5 6 7 |
# File 'lib/smartdown/model/node.rb', line 5 def elements @elements end |
#front_matter ⇒ Object
Returns the value of attribute front_matter
5 6 7 |
# File 'lib/smartdown/model/node.rb', line 5 def front_matter @front_matter end |
#name ⇒ Object
Returns the value of attribute name
5 6 7 |
# File 'lib/smartdown/model/node.rb', line 5 def name @name end |
Instance Method Details
#body ⇒ Object
14 15 16 |
# File 'lib/smartdown/model/node.rb', line 14 def body markdown_blocks_before_question.map { |block| as_markdown(block) }.compact.join("\n") end |
#is_outcome_page_node? ⇒ Boolean
44 45 46 |
# File 'lib/smartdown/model/node.rb', line 44 def is_outcome_page_node? @is_outcome_page_node ||= !is_start_page_node? && !is_question_node? end |
#is_question_node? ⇒ Boolean
40 41 42 |
# File 'lib/smartdown/model/node.rb', line 40 def is_question_node? @is_question_node ||= elements.any?{|element| element.is_a? Smartdown::Model::NextNodeRules} end |
#is_start_page_node? ⇒ Boolean
36 37 38 |
# File 'lib/smartdown/model/node.rb', line 36 def is_start_page_node? @is_start_page_node ||= !! end |
#next_node_rules ⇒ Object
28 29 30 |
# File 'lib/smartdown/model/node.rb', line 28 def next_node_rules @next_node_rules ||= elements.find { |e| e.is_a?(Smartdown::Model::NextNodeRules) } end |
#post_body ⇒ Object
18 19 20 |
# File 'lib/smartdown/model/node.rb', line 18 def post_body markdown_blocks_after_question.map { |block| as_markdown(block) }.compact.join("\n") end |
#questions ⇒ Object
22 23 24 25 26 |
# File 'lib/smartdown/model/node.rb', line 22 def questions @questions ||= elements.select do |element| element.class.to_s.include?("Smartdown::Model::Element::Question") end end |
#start_button ⇒ Object
32 33 34 |
# File 'lib/smartdown/model/node.rb', line 32 def ||= elements.find { |e| e.is_a?(Smartdown::Model::Element::StartButton) } end |
#title ⇒ Object
10 11 12 |
# File 'lib/smartdown/model/node.rb', line 10 def title h1s.first ? h1s.first.content : "" end |