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



20
21
22
# File 'lib/smartdown/model/node.rb', line 20

def body
  markdown_blocks[1..-1].map { |block| as_markdown(block) }.compact.join("\n")
end

#questionsObject



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

def questions
  elements.select do |element|
    element.class.to_s.include?("Smartdown::Model::Element::Question")
  end
end

#titleObject



16
17
18
# File 'lib/smartdown/model/node.rb', line 16

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