Class: MarkdownToRspec::ToRspec::Item::Heading

Inherits:
Base
  • Object
show all
Defined in:
lib/markdown_to_rspec/to_rspec/item/heading.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#indent

Constructor Details

#initialize(level:, text:, parent: nil, children: []) ⇒ Heading



7
8
9
10
11
12
13
14
# File 'lib/markdown_to_rspec/to_rspec/item/heading.rb', line 7

def initialize(level:, text:, parent: nil, children: [])
  @level = level
  @text = text
  @parent = parent
  @children = children
  # If there is a parent, nest it and add it to the parent's child elements.
  @depth = parent ? parent.depth + 1 : 0
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



17
18
19
# File 'lib/markdown_to_rspec/to_rspec/item/heading.rb', line 17

def children
  @children
end

#depthObject (readonly)

Returns the value of attribute depth.



16
17
18
# File 'lib/markdown_to_rspec/to_rspec/item/heading.rb', line 16

def depth
  @depth
end

#levelObject (readonly)

Returns the value of attribute level.



16
17
18
# File 'lib/markdown_to_rspec/to_rspec/item/heading.rb', line 16

def level
  @level
end

#parentObject (readonly)

Returns the value of attribute parent.



16
17
18
# File 'lib/markdown_to_rspec/to_rspec/item/heading.rb', line 16

def parent
  @parent
end

#textObject (readonly)

Returns the value of attribute text.



16
17
18
# File 'lib/markdown_to_rspec/to_rspec/item/heading.rb', line 16

def text
  @text
end

Instance Method Details

#convertObject



19
20
21
22
23
24
25
# File 'lib/markdown_to_rspec/to_rspec/item/heading.rb', line 19

def convert
  template(level_to_syntax, text)
    .split("\n")
    .map { |line| indent(line) }
    .insert(1, convert_children) # Insert the result of a child element between do...end.
    .join("\n")
end