Class: MarkdownToRspec::ToRspec::Item::Heading
- Defined in:
- lib/markdown_to_rspec/to_rspec/item/heading.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize(level:, text:, parent: nil, children: []) ⇒ Heading
constructor
A new instance of Heading.
Methods inherited from Base
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
#children ⇒ Object
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 |
#depth ⇒ Object (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 |
#level ⇒ Object (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 |
#parent ⇒ Object (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 |
#text ⇒ Object (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
#convert ⇒ Object
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 |