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



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



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

def elements
  @elements
end

#front_matterObject

Returns the value of attribute 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



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

#h1sObject



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

def h1s
  elements_of_kind(Smartdown::Model::Element::MarkdownHeading)
end

#markdown_blocksObject



18
19
20
# File 'lib/smartdown/model/node.rb', line 18

def markdown_blocks
  elements_of_kind(Smartdown::Model::Element::MarkdownHeading, Smartdown::Model::Element::MarkdownParagraph)
end

#questionsObject



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

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

#titleObject



14
15
16
# File 'lib/smartdown/model/node.rb', line 14

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