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.
-
#question_titles ⇒ Object
Because question titles and page titles use the same markdown, there are at least as many or more headings than questions on each page To get only the question titles, we are assuming that all the headings that are not question headings come first in the markdown, then question headings.
- #questions ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(name, elements, front_matter = nil) ⇒ Node
Returns a new instance of 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
26 27 28 |
# File 'lib/smartdown/model/node.rb', line 26 def body markdown_blocks[1..-1].map { |block| as_markdown(block) }.compact.join("\n") end |
#question_titles ⇒ Object
Because question titles and page titles use the same markdown, there are at least as many or more headings than questions on each page To get only the question titles, we are assuming that all the headings that are not question headings come first in the markdown, then question headings
18 19 20 |
# File 'lib/smartdown/model/node.rb', line 18 def question_titles h1s.drop(h1s.count - questions.count) end |
#questions ⇒ Object
10 11 12 |
# File 'lib/smartdown/model/node.rb', line 10 def questions elements_of_kind(Smartdown::Model::Element::MultipleChoice) end |
#title ⇒ Object
22 23 24 |
# File 'lib/smartdown/model/node.rb', line 22 def title h1s.first ? h1s.first.content : "" end |