Class: Smartdown::Model::Node

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#elementsObject

Returns the value of attribute elements

Returns:

  • (Object)

    the current value of elements



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

def elements
  @elements
end

#front_matterObject

Returns the value of attribute front_matter

Returns:

  • (Object)

    the current value of front_matter



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

def front_matter
  @front_matter
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



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

def name
  @name
end

Instance Method Details

#bodyObject



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_titlesObject

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

#questionsObject



10
11
12
# File 'lib/smartdown/model/node.rb', line 10

def questions
  elements_of_kind(Smartdown::Model::Element::MultipleChoice)
end

#titleObject



22
23
24
# File 'lib/smartdown/model/node.rb', line 22

def title
  h1s.first ? h1s.first.content : ""
end